diff --git a/lib/config b/lib/config index a0b9b0a6f6..b44e79aa3d 100644 --- a/lib/config +++ b/lib/config @@ -96,8 +96,17 @@ function merge_config_file { next } /^[^ \t]+/ { - split($0, d, " *= *") - print "iniset " configfile " " section " " d[1] " \x27" d[2] "\x27 " + # get offset of first '=' in $0 + eq_idx = index($0, "=") + # extract attr & value from $0 + attr = substr($0, 1, eq_idx - 1) + value = substr($0, eq_idx + 1) + # only need to strip trailing whitespace from attr + sub(/[ \t]*$/, "", attr) + # need to strip leading & trailing whitespace from value + sub(/^[ \t]*/, "", value) + sub(/[ \t]*$/, "", value) + print "iniset " configfile " " section " " attr " \x27" value "\x27" } ' | while read a; do eval "$a"; done diff --git a/tests/test_config.sh b/tests/test_config.sh index 7cf75d0c4f..6fff29c396 100755 --- a/tests/test_config.sh +++ b/tests/test_config.sh @@ -95,6 +95,15 @@ type=new [[test-quote|test-quote.conf]] [foo] foo="foo bar" "baz" + +[[test5|test-equals.conf]] +[DEFAULT] +drivers = driver=python.import.path.Driver + +[[test6|test-strip.conf]] +[DEFAULT] +# next line has trailing space +attr = strip_trailing_space EOF echo -n "get_meta_section_files: test0 doesn't exist: " @@ -238,5 +247,25 @@ EXPECT_VAL=" type = new" check_result "$VAL" "$EXPECT_VAL" -rm -f test.conf test1c.conf test2a.conf test-quote.conf test-space.conf +echo -n "merge_config_file test5 equals in value: " +rm -f test-equals.conf +merge_config_file test.conf test5 test-equals.conf +VAL=$(cat test-equals.conf) +# iniset adds a blank line if it creates the file... +EXPECT_VAL=" +[DEFAULT] +drivers = driver=python.import.path.Driver" +check_result "$VAL" "$EXPECT_VAL" + +echo -n "merge_config_file test6 value stripped: " +rm -f test-strip.conf +merge_config_file test.conf test6 test-strip.conf +VAL=$(cat test-strip.conf) +# iniset adds a blank line if it creates the file... +EXPECT_VAL=" +[DEFAULT] +attr = strip_trailing_space" +check_result "$VAL" "$EXPECT_VAL" + +rm -f test.conf test1c.conf test2a.conf test-quote.conf test-space.conf test-equals.conf test-strip.conf rm -rf test-etc