diff --git a/src/View/Antlers/Parser.php b/src/View/Antlers/Parser.php index 3017bd05c0..f230d306b2 100644 --- a/src/View/Antlers/Parser.php +++ b/src/View/Antlers/Parser.php @@ -66,10 +66,10 @@ class Parser public function __construct() { // Matches a variable inside curly braces. Spaces not allowed. - $this->variableRegex = "(?!if\s|unless\s)[a-zA-Z0-9_'\"][^<>{}=\s]*"; + $this->variableRegex = "(?!if\s|unless\s)[a-zA-Z0-9_'\"][^{}=\s]*"; // Matches a full variable expression inside curly braces. - $this->looseVariableRegex = "(?!if\s|unless\s)[a-zA-Z0-9_'\"][^<>{}=]*"; + $this->looseVariableRegex = "(?!if\s|unless\s)[a-zA-Z0-9_'\"][^{}=]*"; // Matches the first part of a {{ tag: followed a variable name and full expression. $this->callbackNameRegex = '(?!if\s|unless\s)[a-zA-Z0-9_][^<>{}=!?]*'.':'.$this->variableRegex; diff --git a/tests/View/Antlers/ParserTest.php b/tests/View/Antlers/ParserTest.php index 1e67566bcd..0277613ec7 100644 --- a/tests/View/Antlers/ParserTest.php +++ b/tests/View/Antlers/ParserTest.php @@ -413,6 +413,16 @@ public function testNullCoalescence() $this->assertEquals('Pass', $this->parse('{{ missing[thing] ?? "Pass" }}', $this->variables)); } + public function testNullCoalescenceWithStringModifiers() + { + $this->assertEquals('HELLO WILDERNESS', $this->parse('{{ missing ?? string | upper }}', $this->variables)); + $this->assertEquals('HELLO WILDERNESS', $this->parse('{{ missing | upper ?? string | upper }}', $this->variables)); + $this->assertEquals('HELLO WILDERNESS', $this->parse('{{ string | upper ?? missing | upper }}', $this->variables)); + + // With parameters + $this->assertEquals('Hello wilderness >', $this->parse('{{ missing ?? string | ensure_right: > }}', $this->variables)); + } + public function testTruthCoalescing() { $this->assertEquals('Pass', $this->parse('{{ string ?= "Pass" }}', $this->variables));