Merge pull request #646 from YunoHost/fix_getopts

[fix] Escape double quote before eval in getopts
This commit is contained in:
Maniack Crudelis 2019-02-11 15:27:41 +01:00 committed by GitHub
commit 2d3ff79683
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -150,6 +150,9 @@ ynh_handle_getopts_args () {
# If there's already another value for this option, add a ; before adding the new value # If there's already another value for this option, add a ; before adding the new value
eval ${option_var}+="\;" eval ${option_var}+="\;"
fi fi
# Escape double quote to prevent any interpretation during the eval
all_args[$i]="${all_args[$i]//\"/\\\"}"
eval ${option_var}+=\"${all_args[$i]}\" eval ${option_var}+=\"${all_args[$i]}\"
shift_value=$(( shift_value + 1 )) shift_value=$(( shift_value + 1 ))
fi fi
@ -188,6 +191,9 @@ ynh_handle_getopts_args () {
# The variable name will be stored in 'option_var' # The variable name will be stored in 'option_var'
local option_var="${args_array[$option_flag]%=}" local option_var="${args_array[$option_flag]%=}"
# Escape double quote to prevent any interpretation during the eval
arguments[$i]="${arguments[$i]//\"/\\\"}"
# Store each value given as argument in the corresponding variable # Store each value given as argument in the corresponding variable
# The values will be stored in the same order than $args_array # The values will be stored in the same order than $args_array
eval ${option_var}+=\"${arguments[$i]}\" eval ${option_var}+=\"${arguments[$i]}\"