diff --git a/inc/ini-config b/inc/ini-config index 68d48d197b..6fe7788158 100644 --- a/inc/ini-config +++ b/inc/ini-config @@ -200,7 +200,7 @@ $option = $value local sep sep=$(echo -ne "\x01") # Replace it - $sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file" + $sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('"${option}"'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file" fi $xtrace } diff --git a/tests/test_ini_config.sh b/tests/test_ini_config.sh index a5e110736e..f7dc89a28d 100755 --- a/tests/test_ini_config.sh +++ b/tests/test_ini_config.sh @@ -44,6 +44,9 @@ empty = multi = foo1 multi = foo2 +[key_with_spaces] +rgw special key = something + # inidelete(a) [del_separate_options] a=b @@ -82,8 +85,9 @@ fi # test iniget_sections VAL=$(iniget_sections "${TEST_INI}") -assert_equal "$VAL" "default aaa bbb ccc ddd eee del_separate_options \ -del_same_option del_missing_option del_missing_option_multi del_no_options" +assert_equal "$VAL" "default aaa bbb ccc ddd eee key_with_spaces \ +del_separate_options del_same_option del_missing_option \ +del_missing_option_multi del_no_options" # Test with missing arguments BEFORE=$(cat ${TEST_INI}) @@ -209,6 +213,20 @@ iniset $SUDO_ARG ${INI_TMP_ETC_DIR}/test.new.ini test foo bar VAL=$(iniget ${INI_TMP_ETC_DIR}/test.new.ini test foo) assert_equal "$VAL" "bar" "iniset created file" +# test creation of keys with spaces +iniset ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw another key" somethingelse +VAL=$(iniget ${TEST_INI} key_with_spaces "rgw another key") +assert_equal "$VAL" "somethingelse" "iniset created a key with spaces" + +# test update of keys with spaces +iniset ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw special key" newvalue +VAL=$(iniget ${TEST_INI} key_with_spaces "rgw special key") +assert_equal "$VAL" "newvalue" "iniset updated a key with spaces" + +inidelete ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw another key" +VAL=$(iniget ${TEST_INI} key_with_spaces "rgw another key") +assert_empty VAL "inidelete removed a key with spaces" + $SUDO rm -rf ${INI_TMP_DIR} report_results