Skip to content

Commit c7c6765

Browse files
committed
iniset: fix handling of keys with spaces
Ceph for example uses them. Creation already worked, but not updates of existing keys. Closes-Bug: 1774956 Change-Id: I20cb61c08079b9cd9ad56ac875525abf1442bff6
1 parent 0d1bee1 commit c7c6765

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

inc/ini-config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ $option = $value
200200
local sep
201201
sep=$(echo -ne "\x01")
202202
# Replace it
203-
$sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
203+
$sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('"${option}"'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
204204
fi
205205
$xtrace
206206
}

tests/test_ini_config.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ empty =
4444
multi = foo1
4545
multi = foo2
4646
47+
[key_with_spaces]
48+
rgw special key = something
49+
4750
# inidelete(a)
4851
[del_separate_options]
4952
a=b
@@ -82,8 +85,9 @@ fi
8285

8386
# test iniget_sections
8487
VAL=$(iniget_sections "${TEST_INI}")
85-
assert_equal "$VAL" "default aaa bbb ccc ddd eee del_separate_options \
86-
del_same_option del_missing_option del_missing_option_multi del_no_options"
88+
assert_equal "$VAL" "default aaa bbb ccc ddd eee key_with_spaces \
89+
del_separate_options del_same_option del_missing_option \
90+
del_missing_option_multi del_no_options"
8791

8892
# Test with missing arguments
8993
BEFORE=$(cat ${TEST_INI})
@@ -209,6 +213,20 @@ iniset $SUDO_ARG ${INI_TMP_ETC_DIR}/test.new.ini test foo bar
209213
VAL=$(iniget ${INI_TMP_ETC_DIR}/test.new.ini test foo)
210214
assert_equal "$VAL" "bar" "iniset created file"
211215

216+
# test creation of keys with spaces
217+
iniset ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw another key" somethingelse
218+
VAL=$(iniget ${TEST_INI} key_with_spaces "rgw another key")
219+
assert_equal "$VAL" "somethingelse" "iniset created a key with spaces"
220+
221+
# test update of keys with spaces
222+
iniset ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw special key" newvalue
223+
VAL=$(iniget ${TEST_INI} key_with_spaces "rgw special key")
224+
assert_equal "$VAL" "newvalue" "iniset updated a key with spaces"
225+
226+
inidelete ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw another key"
227+
VAL=$(iniget ${TEST_INI} key_with_spaces "rgw another key")
228+
assert_empty VAL "inidelete removed a key with spaces"
229+
212230
$SUDO rm -rf ${INI_TMP_DIR}
213231

214232
report_results

0 commit comments

Comments
 (0)