Skip to content

Commit 28ee346

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "iniset: fix handling of values containg ampersand"
2 parents ea82eff + d266c87 commit 28ee346

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

inc/ini-config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ function iniset {
189189
local option=$3
190190
local value=$4
191191

192+
# Escape the ampersand character (&)
193+
value=$(echo $value | sed -e 's/&/\\&/g')
194+
192195
if [[ -z $section || -z $option ]]; then
193196
$xtrace
194197
return

tests/test_ini_config.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ empty =
4444
multi = foo1
4545
multi = foo2
4646
47+
[fff]
48+
ampersand =
49+
4750
[key_with_spaces]
4851
rgw special key = something
4952
@@ -85,7 +88,7 @@ fi
8588

8689
# test iniget_sections
8790
VAL=$(iniget_sections "${TEST_INI}")
88-
assert_equal "$VAL" "default aaa bbb ccc ddd eee key_with_spaces \
91+
assert_equal "$VAL" "default aaa bbb ccc ddd eee fff key_with_spaces \
8992
del_separate_options del_same_option del_missing_option \
9093
del_missing_option_multi del_no_options"
9194

@@ -124,6 +127,13 @@ iniset ${SUDO_ARG} ${TEST_INI} bbb handlers "33,44"
124127
VAL=$(iniget ${TEST_INI} bbb handlers)
125128
assert_equal "$VAL" "33,44" "inset at EOF"
126129

130+
# Test with ampersand in values
131+
for i in `seq 3`; do
132+
iniset ${TEST_INI} fff ampersand '&y'
133+
done
134+
VAL=$(iniget ${TEST_INI} fff ampersand)
135+
assert_equal "$VAL" "&y" "iniset ampersands in option"
136+
127137
# test empty option
128138
if ini_has_option ${SUDO_ARG} ${TEST_INI} ddd empty; then
129139
passed "ini_has_option: ddd.empty present"

0 commit comments

Comments
 (0)