From 2ac8b3f3c2ebe586802d7789cf152b13fe0d0497 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 4 Dec 2013 17:20:28 -0600 Subject: [PATCH] Fix a couple of INI whitespace bugs * iniset() bails if no section or option (attribute) is supplied * merge_config_file() properly skips lines with only whitespace * Also split the ini-tests into their own script Bug 1257954 Change-Id: Ie31c5bd0df8dfed129fbcf1e37228aaf25e9305d --- functions | 2 + lib/config | 2 +- tests/functions.sh | 189 ------------------------------------- tests/test_config.sh | 18 +++- tests/test_ini.sh | 220 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 240 insertions(+), 191 deletions(-) create mode 100755 tests/test_ini.sh diff --git a/functions b/functions index 5ff4a9b7ca..0280b2bcc4 100644 --- a/functions +++ b/functions @@ -729,6 +729,8 @@ function iniset() { local option=$3 local value=$4 + [[ -z $section || -z $option ]] && return + if ! grep -q "^\[$section\]" "$file" 2>/dev/null; then # Add section at the end echo -e "\n[$section]" >>"$file" diff --git a/lib/config b/lib/config index 91cefe48cc..c28072fc08 100644 --- a/lib/config +++ b/lib/config @@ -95,7 +95,7 @@ function merge_config_file() { /^ *\#/ { next } - /^.+/ { + /^[^ \t]+/ { split($0, d, " *= *") print "iniset " configfile " " section " " d[1] " \"" d[2] "\"" } diff --git a/tests/functions.sh b/tests/functions.sh index 40376aa63f..95dafe1028 100755 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -38,195 +38,6 @@ if [[ $? = 0 ]]; then fi -echo "Testing INI functions" - -cat >test.ini <test.ini <