Skip to content

Commit

Permalink
Support escaping within quoted strings (#36893)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary authored Apr 6, 2021
1 parent 4cc4189 commit e8cdea8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ protected function compileExtensions($value)
protected function compileStatements($value)
{
return preg_replace_callback(
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>\'[^\']*\') | (?>"[^"]*") | (?>[^()\'"]+) | (?3) )* \))?/x', function ($match) {
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>\'(?:\\\\\'|[^\'])*\') | (?>"(?:\\\\"|[^"])*") | (?>[^()\'"]+) | (?3) )* \))?/x', function ($match) {
return $this->compileStatement($match);
}, $value
);
Expand Down
15 changes: 15 additions & 0 deletions tests/View/Blade/BladePhpStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,19 @@ public function testStringWithEmptyStringDataValue()

$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testStringWithEscapingDataValue()
{
$string = "@php(\$data = ['test' => 'won\\'t break'])";

$expected = "<?php (\$data = ['test' => 'won\\'t break']); ?>";

$this->assertEquals($expected, $this->compiler->compileString($string));

$string = "@php(\$data = ['test' => \"\\\"escaped\\\"\"])";

$expected = "<?php (\$data = ['test' => \"\\\"escaped\\\"\"]); ?>";

$this->assertEquals($expected, $this->compiler->compileString($string));
}
}

0 comments on commit e8cdea8

Please sign in to comment.