Change variable testing behaviour

When checking for emptyness of a variable (In order to support
conditionnals), also check that the variable does not start by "false"
This commit is contained in:
Aurélien Thieriot 2016-07-26 16:42:34 +01:00
parent ea76dc468b
commit ba1ad0dca3
3 changed files with 8 additions and 5 deletions

9
mo
View File

@ -775,15 +775,14 @@ moStandaloneDenied() {
# Internal: Determines if the named thing is a function or if it is a # Internal: Determines if the named thing is a function or if it is a
# non-empty environment variable. # non-empty, not false environment variable.
# #
# Do not use variables without prefixes here if possible as this needs to # Do not use variables without prefixes here if possible as this needs to
# check if any name exists in the environment # check if any name exists in the environment
# #
# $1 - Name of environment variable or function # $1 - Name of environment variable or function
# $2 - Current value (our context)
# #
# Returns 0 if the name is not empty, 1 otherwise. # Returns 0 if the name is not empty nor false, 1 otherwise.
moTest() { moTest() {
# Test for functions # Test for functions
moIsFunction "$1" && return 0 moIsFunction "$1" && return 0
@ -792,8 +791,8 @@ moTest() {
# Arrays must have at least 1 element # Arrays must have at least 1 element
eval '[[ "${#'"$1"'[@]}" -gt 0 ]]' && return 0 eval '[[ "${#'"$1"'[@]}" -gt 0 ]]' && return 0
else else
# Environment variables must not be empty # Environment variables must not be empty nor false
[[ ! -z "${!1}" ]] && return 0 [[ ! -z "${!1}" ]] && eval '[[ "$'"$1"'" != "false" ]]' && return 0
fi fi
return 1 return 1

View File

@ -1 +1,2 @@
person="" person=""
falsy=false

View File

@ -2,3 +2,6 @@ Shown.
{{#person}} {{#person}}
Never shown! Never shown!
{{/person}} {{/person}}
{{#falsy}}
As well !
{{/falsy}}