diff --git a/vendor/ini.class.sh b/vendor/ini.class.sh index d6fced0cd469ddc96ceee4f057a37098c61c1780..9fd7606ad645c5990c17afd7d2e92ee2d3eae0b8 100644 --- a/vendor/ini.class.sh +++ b/vendor/ini.class.sh @@ -251,6 +251,10 @@ function ini.validate(){ local ERROR="\e[1;31mERROR\e[0m" local iErr; typeset -i iErr=0 + if [ ! -f "${myinifile}" ]; then + return 1 + fi + if [ ! -f "${myvalidationfile}" ]; then echo -e "$ERROR: Validation file '${myvalidationfile}' does not exist." return 1 @@ -277,11 +281,12 @@ function ini.validate(){ echo -e "$ERROR: unknown section name: [$section]" iErr+=1 else - test $bShowAll -ne 0 && echo "OK: [$section] ... checking its keys..." + test $bShowAll -ne 0 && echo "OK: section [$section] is valid... checking its keys..." # TODO: verify values for mustkey in $( echo "${varsMust}" | grep "^[/t ]*${section}\." | cut -f 2 -d '.' | cut -f 1 -d ':' ); do - if ini.keys "$myinifile" "$section" | grep "^${mustkey}$"; then + keyregex="$( echo $mustkey | sed -e's,\[,\\[,g' )" + if ini.keys "$myinifile" "$section" | grep "^${keyregex}$"; then test $bShowAll -ne 0 && echo " OK: $section.$mustkey" else echo -e " $ERROR: A MUST key '$mustkey' was not found im section [$section]." @@ -290,10 +295,12 @@ function ini.validate(){ done for mykey in $(ini.keys "$myinifile" "$section"); do + # we need a regex for keys as array eg "file[] = ..." + keyregex="$( echo "${mykey}" | sed -e's,\[,\\[,g' | sed -e's,\],\\],g' )" if ! echo " ${varsMust} ${varsCan} - " | cut -f 1 -d ':' | grep -q "^[/t ]*${section}\.${mykey}$"; then + " | cut -f 1 -d ':' | grep -q "^[/t ]*${section}\.${keyregex}$"; then echo -e " $ERROR: invald key name: $section.$mykey" iErr+=1 else @@ -301,7 +308,7 @@ function ini.validate(){ check=$(echo " ${varsMust} ${varsCan} - " | grep "^[/t ]*${section}\.${mykey}[:$]" | cut -f 2 -d ':' ) + " | grep "^[/t ]*${section}\.${keyregex}[:$]" | cut -f 2 -d ':' ) if [ -n "$check" ]; then value="$(ini.value "$myinifile" "$section" "$mykey")" if ! grep -Eq "^${check}$" <<< "$value" ; then