From e2c9fee8ed846aba124a2fc1bba245790ed7ba90 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 26 Sep 2014 09:42:11 +1000 Subject: [PATCH] Single quote iniset argument in merge_config_file If we don't single quote the extracted argument to iniset we drop any quotes from the source. Add a simple test-case for this. Partial-bug: #1374118 Change-Id: If2f47b64b11015e727a011c7e5f6e8ad378b90eb --- lib/config | 4 +++- tests/test_config.sh | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/config b/lib/config index 0baa4cc3c2..a0b9b0a6f6 100644 --- a/lib/config +++ b/lib/config @@ -82,6 +82,8 @@ function merge_config_file { local matchgroup=$2 local configfile=$3 + # note in the awk below, \x27 is ascii for ' -- this avoids + # having to do nasty quoting games get_meta_section $file $matchgroup $configfile | \ $CONFIG_AWK_CMD -v configfile=$configfile ' BEGIN { section = "" } @@ -95,7 +97,7 @@ function merge_config_file { } /^[^ \t]+/ { split($0, d, " *= *") - print "iniset " configfile " " section " " d[1] " \"" d[2] "\"" + print "iniset " configfile " " section " " d[1] " \x27" d[2] "\x27 " } ' | while read a; do eval "$a"; done diff --git a/tests/test_config.sh b/tests/test_config.sh index 2634ce0654..7cf75d0c4f 100755 --- a/tests/test_config.sh +++ b/tests/test_config.sh @@ -91,6 +91,10 @@ attribute=value [[test4|\$TEST4_DIR/\$TEST4_FILE]] [fff] type=new + +[[test-quote|test-quote.conf]] +[foo] +foo="foo bar" "baz" EOF echo -n "get_meta_section_files: test0 doesn't exist: " @@ -206,6 +210,15 @@ EXPECT_VAL=" attribute = value" check_result "$VAL" "$EXPECT_VAL" +echo -n "merge_config_file test-quote: " +rm -f test-quote.conf +merge_config_file test.conf test-quote test-quote.conf +VAL=$(cat test-quote.conf) +EXPECT_VAL=' +[foo] +foo = "foo bar" "baz"' +check_result "$VAL" "$EXPECT_VAL" + echo -n "merge_config_group test4 variable filename: " setup_test4 merge_config_group test.conf test4 @@ -225,5 +238,5 @@ EXPECT_VAL=" type = new" check_result "$VAL" "$EXPECT_VAL" -rm -f test.conf test1c.conf test2a.conf test-space.conf +rm -f test.conf test1c.conf test2a.conf test-quote.conf test-space.conf rm -rf test-etc