Skip to content

Commit

Permalink
Antlers: Prevent isConditionProcessor from leaking on else branches (
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster authored May 6, 2023
1 parent fdfe4d1 commit 7e01ac2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/View/Antlers/Language/Runtime/ConditionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function process(ConditionNode $node, $data)

foreach ($node->logicBranches as $branch) {
if ($branch->head->name->name == 'else') {
$this->processor->setIsConditionProcessor($condValueToRestore);

return $branch;
} else {
// Let the processor know that it is being used
Expand Down
24 changes: 24 additions & 0 deletions tests/Antlers/Runtime/YieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,28 @@ public function test_yield_can_be_used_inside_conditions()

$this->assertSame('', trim($this->renderString($template, [], true)));
}

public function test_condition_blocks_do_not_leak_their_condition_state()
{
$template = <<<'EOT'
{{ if false }}
{{# It doesn't matter whats inside here #}}
{{ else }}
Else Statement.
{{ /if }}
{{ section:seo_body }}Content{{ section:seo_body }}
{{ yield:seo_body }}
EOT;

$expected = <<<'EXPECTED'
Else Statement.
Content
EXPECTED;

$this->assertSame($expected, trim($this->renderString($template, [], true)));
}
}

0 comments on commit 7e01ac2

Please sign in to comment.