diff --git a/inc/ini-config b/inc/ini-config index 79936823d2..f65e42d3a5 100644 --- a/inc/ini-config +++ b/inc/ini-config @@ -189,6 +189,9 @@ function iniset { local option=$3 local value=$4 + # Escape the ampersand character (&) + value=$(echo $value | sed -e 's/&/\\&/g') + if [[ -z $section || -z $option ]]; then $xtrace return diff --git a/tests/test_ini_config.sh b/tests/test_ini_config.sh index 6ed1647f34..6367cde441 100755 --- a/tests/test_ini_config.sh +++ b/tests/test_ini_config.sh @@ -44,6 +44,9 @@ empty = multi = foo1 multi = foo2 +[fff] +ampersand = + [key_with_spaces] rgw special key = something @@ -85,7 +88,7 @@ fi # test iniget_sections VAL=$(iniget_sections "${TEST_INI}") -assert_equal "$VAL" "default aaa bbb ccc ddd eee key_with_spaces \ +assert_equal "$VAL" "default aaa bbb ccc ddd eee fff key_with_spaces \ del_separate_options del_same_option del_missing_option \ del_missing_option_multi del_no_options" @@ -124,6 +127,13 @@ iniset ${SUDO_ARG} ${TEST_INI} bbb handlers "33,44" VAL=$(iniget ${TEST_INI} bbb handlers) assert_equal "$VAL" "33,44" "inset at EOF" +# Test with ampersand in values +for i in `seq 3`; do + iniset ${TEST_INI} fff ampersand '&y' +done +VAL=$(iniget ${TEST_INI} fff ampersand) +assert_equal "$VAL" "&y" "iniset ampersands in option" + # test empty option if ini_has_option ${SUDO_ARG} ${TEST_INI} ddd empty; then passed "ini_has_option: ddd.empty present"