From 22a27b494f7e7399f53acf564b94f9267b446511 2020-07-06 16:13:44
From: Branko Majic <branko@majic.rs>
Date: 2020-07-06 16:13:44
Subject: [PATCH] Noticket: [factorio_manager.sh] Expand checks for bool/int values to achieve better correctness of the code:

A && B || C in Bash is not equivalent to:

if A; then
    B
else
    C
fi

In fact, if A is true, and B is false, C will still get run.

In this particular case it's not a problem, but better to get rid of
it and have slightly longer code.

---

diff --git a/games/factorio_manager.sh b/games/factorio_manager.sh
index e4b36b751d0160b1215157ebd2426b906b9be8d5..4a0e5233c50c2864e77338430163285e974dbaba 100755
--- a/games/factorio_manager.sh
+++ b/games/factorio_manager.sh
@@ -493,10 +493,18 @@ function validate_server_setting_value() {
     local result=1
 
     if [[ $type == "bool" ]]; then
-        [[ $value == true || $value == false ]] && result=0 || colorecho "red" "$name must be a boolean [true|false]."
+        if [[ $value == true || $value == false ]]; then
+            result=0
+        else
+            colorecho "red" "$name must be a boolean [true|false]."
+        fi
 
     elif [[ $type == "int" ]]; then
-        [[ $value =~ ^[[:digit:]]+$ ]] && result=0 || colorecho "red" "$name must be a number."
+        if [[ $value =~ ^[[:digit:]]+$ ]]; then
+            result=0
+        else
+            colorecho "red" "$name must be a number."
+        fi
 
     elif [[ $type == "str" ]]; then
         result=0