Skip to content

Commit

Permalink
FIX: template parser erroring on strings partially matching true/fals…
Browse files Browse the repository at this point in the history
…e/null
  • Loading branch information
kinglozzer committed Oct 5, 2018
1 parent 01ba4f1 commit 3dcfc64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/View/SSTemplateParser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,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

Expand Down
8 changes: 4 additions & 4 deletions src/View/SSTemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1151,23 +1151,23 @@ function match_QuotedString ($stack = array()) {
}


/* 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);
}
else { return FALSE; }
}


/* 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);
}
Expand Down
9 changes: 6 additions & 3 deletions tests/php/View/SSViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,12 @@ public function typePreservationDataProvider()
['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'],
Expand Down

0 comments on commit 3dcfc64

Please sign in to comment.