Browse Source

fix: dev: [apache] a little more solid ``apache-custom-rules`` reading.

framadate
Valentin Lab 5 years ago
parent
commit
1366b29460
  1. 7
      apache/lib/common
  2. 68
      apache/test/custom_rules

7
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")
;;

68
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'
Loading…
Cancel
Save