Merge "iniset: fix handling of keys with spaces"

This commit is contained in:
Zuul 2018-06-12 08:25:46 +00:00 committed by Gerrit Code Review
commit d2e82a411d
2 changed files with 21 additions and 3 deletions

View File

@ -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
}

View File

@ -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