Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Change @ to backslash to prevent parsing Antlers within tag parameters #9856

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/View/Antlers/Language/Parser/AntlersNodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ private function getParameters(AntlersNode $node)

if ($hasFoundName == false && $current == DocumentParser::Punctuation_Equals) {
if (! empty($currentChars)) {
if (! (ctype_alpha($currentChars[0]) || ctype_digit($currentChars[0]) || $currentChars[0] == DocumentParser::Punctuation_Colon || $currentChars[0] == DocumentParser::AtChar)) {
if (! (ctype_alpha($currentChars[0]) || ctype_digit($currentChars[0]) || $currentChars[0] == DocumentParser::Punctuation_Colon || $currentChars[0] == DocumentParser::AtChar || $currentChars[0] == DocumentParser::String_EscapeCharacter)) {
$currentChars = [];

continue;
Expand Down Expand Up @@ -672,7 +672,7 @@ private function getParameters(AntlersNode $node)
}
}

if (Str::startsWith($name, DocumentParser::AtChar)) {
if (Str::startsWith($name, DocumentParser::String_EscapeCharacter)) {
$parameterNode->containsEscapedContent = true;
$name = mb_substr($name, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/View/Antlers/Language/Parser/DocumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ private function scanToEndOfAntlersRegion()
}
}

if ($this->cur == self::AtChar && ($this->prev != null && ctype_space($this->prev))) {
if ($this->cur == self::String_EscapeCharacter && ($this->prev != null && ctype_space($this->prev))) {
if ($this->next != null && (ctype_alpha($this->next) || $this->next == self::Punctuation_Underscore || $this->next == self::AtChar)) {
// It is possible that we might be starting some escaped content.
// We will need more information to determine this, but let's
Expand Down
12 changes: 6 additions & 6 deletions tests/Antlers/Parser/NodeParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function test_double_braces_inside_a_parameter_emits_final_literal_node_i
$this->assertSame('FINAL_LITERAL</figure>', $nodes[2]->content);

$template = <<<'EOT'
<div class="list-of-classes"> {{ partial src="svg/" values="{{ article_icon_color:key }} {{ article_icon_size:key }}" }}FINAL_LITERAL </div>
<div class="list-of-classes"> {{ partial src="svg/" values="{{ article_icon_color:key }} {{ article_icon_size:key }}" }}FINAL_LITERAL </div>
EOT;

$nodes = $this->parseNodes($template);
Expand All @@ -263,7 +263,7 @@ public function test_double_braces_inside_a_parameter_emits_final_literal_node_i
$this->assertInstanceOf(LiteralNode::class, $nodes[2]);

$this->assertSame(' <div class="list-of-classes"> ', $nodes[0]->content);
$this->assertSame('FINAL_LITERAL </div> ', $nodes[2]->content);
$this->assertSame('FINAL_LITERAL </div>', $nodes[2]->content);
}

public function test_shorthand_variable_syntax()
Expand Down Expand Up @@ -332,7 +332,7 @@ public function test_it_parses_shorthand_parameters_and_regular_parameters()
public function test_curly_braces_inside_a_parameter_can_be_ignored_entirely()
{
$template = <<<'EOT'
{{ form @x-data="{ open: false }" @attr:x-bind="..." @x-init="() => { open = true }" x-show="open" }}
{{ form \x-data="{ open: false }" \attr:x-bind="..." \x-init="() => { open = true }" x-show="open" }}
EOT;

$nodes = $this->parseNodes($template);
Expand All @@ -348,17 +348,17 @@ public function test_curly_braces_inside_a_parameter_can_be_ignored_entirely()

$pXData = $antlersNode->parameters[0];
$this->assertSame('x-data', $pXData->name);
$this->assertSame('@x-data', $pXData->originalName);
$this->assertSame('\x-data', $pXData->originalName);
$this->assertSame('{ open: false }', $pXData->value);

$pXBind = $antlersNode->parameters[1];
$this->assertSame('attr:x-bind', $pXBind->name);
$this->assertSame('@attr:x-bind', $pXBind->originalName);
$this->assertSame('\attr:x-bind', $pXBind->originalName);
$this->assertSame('...', $pXBind->value);

$pXInit = $antlersNode->parameters[2];
$this->assertSame('x-init', $pXInit->name);
$this->assertSame('@x-init', $pXInit->originalName);
$this->assertSame('\x-init', $pXInit->originalName);
$this->assertSame('() => { open = true }', $pXInit->value);

$pXShow = $antlersNode->parameters[3];
Expand Down
Loading