From 3a6c48cddbccf1f467993e2838daaa1d6602d41b Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 5 Oct 2018 12:47:04 +0100 Subject: [PATCH] FIX: template parser erroring on strings partially matching true/false/null --- src/View/SSTemplateParser.peg | 4 ++-- src/View/SSTemplateParser.php | 8 ++++---- tests/php/View/SSViewerTest.php | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/View/SSTemplateParser.peg b/src/View/SSTemplateParser.peg index 163a9bfd1..9f77e0940 100644 --- a/src/View/SSTemplateParser.peg +++ b/src/View/SSTemplateParser.peg @@ -418,11 +418,11 @@ class SSTemplateParser extends Parser implements TemplateParser # Null - Null: / null /i + Null: / (null)\b /i # Booleans - Boolean: / (true|false) /i + Boolean: / (true|false)\b /i # Integers and floats diff --git a/src/View/SSTemplateParser.php b/src/View/SSTemplateParser.php index a906dfac1..8d5221c35 100644 --- a/src/View/SSTemplateParser.php +++ b/src/View/SSTemplateParser.php @@ -1217,11 +1217,11 @@ class SSTemplateParser extends Parser implements TemplateParser } - /* Null: / null /i */ + /* Null: / (null)\b /i */ protected $match_Null_typestack = array('Null'); function match_Null ($stack = array()) { $matchrule = "Null"; $result = $this->construct($matchrule, $matchrule, null); - if (( $subres = $this->rx( '/ null /i' ) ) !== FALSE) { + if (( $subres = $this->rx( '/ (null)\b /i' ) ) !== FALSE) { $result["text"] .= $subres; return $this->finalise($result); } @@ -1229,11 +1229,11 @@ class SSTemplateParser extends Parser implements TemplateParser } - /* Boolean: / (true|false) /i */ + /* Boolean: / (true|false)\b /i */ protected $match_Boolean_typestack = array('Boolean'); function match_Boolean ($stack = array()) { $matchrule = "Boolean"; $result = $this->construct($matchrule, $matchrule, null); - if (( $subres = $this->rx( '/ (true|false) /i' ) ) !== FALSE) { + if (( $subres = $this->rx( '/ (true|false)\b /i' ) ) !== FALSE) { $result["text"] .= $subres; return $this->finalise($result); } diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php index 766661860..9b6fb67c8 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -724,9 +724,12 @@ after' ['boolean:1', 'TRUE'], ['boolean:', 'false'], ['boolean:', 'FALSE'], - // Strings which loosely look like booleans - ['string:truthy', 'truthy'], - ['string:falsy', 'falsy'], + // Strings which may look like booleans/null to the parser + ['string:nullish', 'nullish'], + ['string:notnull', 'notnull'], + ['string:truethy', 'truethy'], + ['string:untrue', 'untrue'], + ['string:falsey', 'falsey'], // Integers ['integer:0', '0'], ['integer:1', '1'],