Skip to content

Commit b0f9dc6

Browse files
committed
Support escaping within quoted strings
1 parent 4cc4189 commit b0f9dc6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Illuminate/View/Compilers/BladeCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ protected function compileExtensions($value)
417417
protected function compileStatements($value)
418418
{
419419
return preg_replace_callback(
420-
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>\'[^\']*\') | (?>"[^"]*") | (?>[^()\'"]+) | (?3) )* \))?/x', function ($match) {
420+
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>\'(?:\\\\\'|[^\'])*\') | (?>"(?:\\\\"|[^"])*") | (?>[^()\'"]+) | (?3) )* \))?/x', function ($match) {
421421
return $this->compileStatement($match);
422422
}, $value
423423
);

tests/View/Blade/BladePhpStatementsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,19 @@ public function testStringWithEmptyStringDataValue()
6767

6868
$this->assertEquals($expected, $this->compiler->compileString($string));
6969
}
70+
71+
public function testStringWithEscapingDataValue()
72+
{
73+
$string = "@php(\$data = ['test' => 'won\\'t break'])";
74+
75+
$expected = "<?php (\$data = ['test' => 'won\\'t break']); ?>";
76+
77+
$this->assertEquals($expected, $this->compiler->compileString($string));
78+
79+
$string = "@php(\$data = ['test' => \"\\\"escaped\\\"\"])";
80+
81+
$expected = "<?php (\$data = ['test' => \"\\\"escaped\\\"\"]); ?>";
82+
83+
$this->assertEquals($expected, $this->compiler->compileString($string));
84+
}
7085
}

0 commit comments

Comments
 (0)