From ad978ac39cbc137646230555be371e051393dfac 2020-07-06 15:55:41
From: Branko Majic <branko@majic.rs>
Date: 2020-07-06 15:55:41
Subject: [PATCH] Noticket: [factorio_manager.sh] Use quotes around right-hand sides of operators:

- Right-hand side is treated as glob, so quoting is necessary to avoid
  errors. For example, if var='[a]', then [[ $a == $a ]] will always
  be false.

---

diff --git a/games/factorio_manager.sh b/games/factorio_manager.sh
index df8e2dd3affd8d2b1583e5fb9e637cf1bfb8fd58..3fed87f13a1cb4f163e72eff3529cb5d226758f8 100755
--- a/games/factorio_manager.sh
+++ b/games/factorio_manager.sh
@@ -510,7 +510,7 @@ function validate_server_setting_value() {
 
         for i in "${possible_values[@]}"; do
             # Allow strings without quotes to be specified by the user.
-            [[ $value == $i || \"$value\" == $i ]] && result=0
+            [[ $value == "$i" || \"$value\" == "$i" ]] && result=0
         done
 
         [[ $result == 0 ]] || colorecho red "$name must be one of listed values [$type]."
@@ -866,7 +866,7 @@ function read_server_settings() {
 
             for i in "${possible_values[@]}"; do
                 # Convenience for allowing strings without quotes specified by the user.
-                [[ \"${settings_value[$key]}\" == $i ]] && settings_value[$key]="\"${settings_value[$key]}\""
+                [[ \"${settings_value[$key]}\" == "$i" ]] && settings_value[$key]="\"${settings_value[$key]}\""
             done
 
         # List of strings.
@@ -1060,8 +1060,8 @@ function select_factorio_version() {
         echo -n "  [$i] $(basename "${game_versions_available[$i-1]}")"
 
         # Highlight default version.
-        if [[ -z $default_version && $i == ${#game_versions_available[@]} ]] || \
-               [[ -n $default_version && ${game_versions_available[i-1]} == $default_version ]]; then
+        if [[ -z $default_version && $i == "${#game_versions_available[@]}" ]] || \
+               [[ -n $default_version && ${game_versions_available[i-1]} == "$default_version" ]]; then
             colorecho boldgreen " [$default_marker]"
             default_option="$i"
         else
@@ -1386,7 +1386,7 @@ elif [[ $command == launch ]]; then
     current_write_data=$(grep "^write-data=" "$game_config")
     expected_write_data="write-data=${instance_directory}"
 
-    if [[ $current_write_data != $expected_write_data ]]; then
+    if [[ $current_write_data != "$expected_write_data" ]]; then
         warning "Incorrect path specified for write-data in game configuration file: $game_config"
         warning "Current configuration is: $current_write_data"
         warning "Configuration will be replaced with: $expected_write_data"
@@ -1758,7 +1758,7 @@ elif [[ $command == set-version ]]; then
     echo
 
     # Change instance game version.
-    if [[ $game_version_selected == $game_version ]]; then
+    if [[ $game_version_selected == "$game_version" ]]; then
         info "Current version has been kept."
     else
         sed -i -e "s/^game_version=.*/game_version=$game_version_selected/" "$instance_config"