From 70cc736b4a4f3bf76cf6392fdf509059c29272ff Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Fri, 21 Aug 2015 11:56:52 -0500 Subject: [PATCH] Must have IFS set properly This lets the value returned from mustache-is-standalone get parsed correctly. When this is a standalone template, the value returned looks like "12 34" where each number is a position. Later, this is used in a line that looks like `( $VALUE_RETURNED )`. When IFS does not contain a space, this array is not built correctly. --- mo | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mo b/mo index 07da321..c7da112 100755 --- a/mo +++ b/mo @@ -289,14 +289,14 @@ mustache-is-standalone() { if [[ "$CHAR" != $'\n' ]] && [[ "$CHAR" != $'\r' ]]; then if [[ ! -z "$CHAR" ]] || ! $4; then - return 1; + return 1 fi fi CHAR=${AFTER_TRIMMED:0:1} if [[ "$CHAR" != $'\n' ]] && [[ "$CHAR" != $'\r' ]] && [[ ! -z "$CHAR" ]]; then - return 2; + return 2 fi if [[ "$CHAR" == $'\r' ]] && [[ "${AFTER_TRIMMED:1:1}" == $'\n' ]]; then @@ -722,5 +722,13 @@ mustache-trim-whitespace() { } -mustache-get-content MUSTACHE_CONTENT "$@" -mustache-parse "$MUSTACHE_CONTENT" "" true +mo() ( + # Execute in a subshell so IFS is reset + IFS=$' \n\t' + mustache-get-content MUSTACHE_CONTENT "$@" + mustache-parse "$MUSTACHE_CONTENT" "" true +) + +if [[ "$0" == "$BASH_SOURCE" ]] || ! [[ -n "$BASH_SOURCE" ]]; then + mo "$@" +fi