mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #685 from randomstuff/shell_escape
Avoid having to shell-escape arguments in ynh_handle_getopts_args
This commit is contained in:
commit
8571ad874f
1 changed files with 2 additions and 11 deletions
|
@ -152,10 +152,6 @@ ynh_handle_getopts_args () {
|
|||
# If there's already another value for this option, add a ; before adding the new value
|
||||
eval ${option_var}+="\;"
|
||||
fi
|
||||
# Escape double quote to prevent any interpretation during the eval
|
||||
all_args[$i]="${all_args[$i]//\"/\\\"}"
|
||||
# Escape $ as well to prevent the string following it to be seen as a variable.
|
||||
all_args[$i]="${all_args[$i]//$/\\\$}"
|
||||
|
||||
# For the record.
|
||||
# We're using eval here to get the content of the variable stored itself as simple text in $option_var...
|
||||
|
@ -164,7 +160,7 @@ ynh_handle_getopts_args () {
|
|||
# declare -g ${option_var} will create a local variable (despite -g !) and will not be available for the helper itself.
|
||||
# So... Stop fucking arguing each time that eval is evil... Go find an other working solution if you can find one!
|
||||
|
||||
eval ${option_var}+=\"${all_args[$i]}\"
|
||||
eval ${option_var}+='"${all_args[$i]}"'
|
||||
shift_value=$(( shift_value + 1 ))
|
||||
fi
|
||||
done
|
||||
|
@ -202,14 +198,9 @@ ynh_handle_getopts_args () {
|
|||
# The variable name will be stored in 'option_var'
|
||||
local option_var="${args_array[$option_flag]%=}"
|
||||
|
||||
# Escape double quote to prevent any interpretation during the eval
|
||||
arguments[$i]="${arguments[$i]//\"/\\\"}"
|
||||
# Escape $ as well to prevent the string following it to be seen as a variable.
|
||||
arguments[$i]="${arguments[$i]//$/\\\$}"
|
||||
|
||||
# Store each value given as argument in the corresponding variable
|
||||
# The values will be stored in the same order than $args_array
|
||||
eval ${option_var}+=\"${arguments[$i]}\"
|
||||
eval ${option_var}+='"${arguments[$i]}"'
|
||||
done
|
||||
unset legacy_args
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue