Skip to content

Commit

Permalink
Allow angle brackets in variables, add tests. Closes #2022.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcdade committed Sep 16, 2020
1 parent 253a8ec commit 521fbfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/View/Antlers/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/View/Antlers/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 521fbfa

Please sign in to comment.