From 1366b2946030ad5ecce3f941113eed6ef76cf1af Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 19 Feb 2019 17:27:38 +0100 Subject: [PATCH] fix: dev: [apache] a little more solid ``apache-custom-rules`` reading. --- apache/lib/common | 7 +++-- apache/test/custom_rules | 68 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 apache/test/custom_rules diff --git a/apache/lib/common b/apache/lib/common index 41b11cd..7b12783 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -618,7 +618,7 @@ EOF _get_custom_rules() { local cfg="$1" custom_rules type elt value first custom_rules=$(e "$cfg" | cfg-get-value apache-custom-rules 2>/dev/null) || true - if [ -z "$custom_rules" ]; then + if [ -z "$custom_rules" -o "$custom_rules" == "None" ]; then return 0 fi type=$(echo "$custom_rules" | shyaml get-type) @@ -632,7 +632,7 @@ _get_custom_rules() { if [ "$first" ]; then first= else - value+=$'\n'$'\n' + value+=$'\n' fi first= value+="$elt" @@ -646,6 +646,9 @@ _get_custom_rules() { "str") value+=$(echo "$custom_rules") ;; + "NoneType") + value="" + ;; *) value+=$(echo "$custom_rules") ;; diff --git a/apache/test/custom_rules b/apache/test/custom_rules new file mode 100644 index 0000000..1207838 --- /dev/null +++ b/apache/test/custom_rules @@ -0,0 +1,68 @@ +#!/bin/bash + +exname=$(basename $0) + +prefix_cmd=" +. /etc/shlib + +include common +include parse + +. ../lib/common + +" + +# mock +cfg-get-value() { + local key="$1" + shyaml get-value "$key" 2>/dev/null +} +export -f cfg-get-value + +yaml_get_interpret() { + shyaml get-value +} +export -f yaml_get_interpret + +## +## Tests +## + +try " +_get_custom_rules ' +'" +noerror +is out '' + + +try " +_get_custom_rules ' +apache-custom-rules: +'" +noerror +is out '' + +try " +_get_custom_rules ' +apache-custom-rules: +- a +- b +'" +noerror +is out 'a +b' + + +try " +_get_custom_rules ' +apache-custom-rules: + a: x + b: y +'" +noerror +is out ' +x +y' + + +