From ba1ad0dca36d4696eb2004e5e4738ffdb45c7690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Thieriot?= Date: Tue, 26 Jul 2016 16:42:34 +0100 Subject: [PATCH] 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" --- mo | 9 ++++----- tests/false-list.env | 1 + tests/false-list.template | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mo b/mo index c12254a..bca858a 100755 --- a/mo +++ b/mo @@ -775,15 +775,14 @@ moStandaloneDenied() { # 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 # check if any name exists in the environment # # $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() { # Test for functions moIsFunction "$1" && return 0 @@ -792,8 +791,8 @@ moTest() { # Arrays must have at least 1 element eval '[[ "${#'"$1"'[@]}" -gt 0 ]]' && return 0 else - # Environment variables must not be empty - [[ ! -z "${!1}" ]] && return 0 + # Environment variables must not be empty nor false + [[ ! -z "${!1}" ]] && eval '[[ "$'"$1"'" != "false" ]]' && return 0 fi return 1 diff --git a/tests/false-list.env b/tests/false-list.env index eef0ddd..5dd12d2 100644 --- a/tests/false-list.env +++ b/tests/false-list.env @@ -1 +1,2 @@ person="" +falsy=false diff --git a/tests/false-list.template b/tests/false-list.template index d67c751..d31d49d 100644 --- a/tests/false-list.template +++ b/tests/false-list.template @@ -2,3 +2,6 @@ Shown. {{#person}} Never shown! {{/person}} +{{#falsy}} + As well ! +{{/falsy}}