From cd7d956fbc30eae3c1694b187ea605a5f0d960d3 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Thu, 5 Dec 2013 08:09:12 +0000 Subject: [PATCH] Handle the case of pipe char in value for iniset iniset did not handle the case of "|" in the value to be injected. Fix this by replacing | with \000 (NULL). Fixes bug #1258050 Change-Id: I8882c2f3f177ebdfa0c66270dbbc7fd50f30b065 --- functions | 3 ++- tests/test_ini.sh | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/functions b/functions index 0280b2bcc4..995be576c7 100644 --- a/functions +++ b/functions @@ -741,8 +741,9 @@ function iniset() { $option = $value " "$file" else + local sep=$(echo -ne "\x01") # Replace it - sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" "$file" + sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file" fi } diff --git a/tests/test_ini.sh b/tests/test_ini.sh index b0dc6b176b..598cd578f6 100755 --- a/tests/test_ini.sh +++ b/tests/test_ini.sh @@ -136,6 +136,26 @@ else echo "iniget failed: $VAL" fi +# test pipe in option +iniset test.ini aaa handlers "a|b" + +VAL=$(iniget test.ini aaa handlers) +if [[ "$VAL" == "a|b" ]]; then + echo "OK: $VAL" +else + echo "iniget failed: $VAL" +fi + +# test space in option +iniset test.ini aaa handlers "a b" + +VAL="$(iniget test.ini aaa handlers)" +if [[ "$VAL" == "a b" ]]; then + echo "OK: $VAL" +else + echo "iniget failed: $VAL" +fi + # Test section not exist VAL=$(iniget test.ini zzz handlers)