Changeset - 22a27b494f7e
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-06 16:13:44
branko@majic.rs
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.
1 file changed with 10 insertions and 2 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -490,16 +490,24 @@ function validate_server_setting_value() {
 
    local i
 

	
 
    # Assume failure.
 
    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
 

	
 
    elif [[ $type == "list" ]]; then
 
        # This is free-form space-delimited list.
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now