diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 4eacd0798b22..e2400af13451 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -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 ); diff --git a/tests/View/Blade/BladePhpStatementsTest.php b/tests/View/Blade/BladePhpStatementsTest.php index 4466fa23c411..89c04120d5bf 100644 --- a/tests/View/Blade/BladePhpStatementsTest.php +++ b/tests/View/Blade/BladePhpStatementsTest.php @@ -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 = " 'won\\'t break']); ?>"; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + + $string = "@php(\$data = ['test' => \"\\\"escaped\\\"\"])"; + + $expected = " \"\\\"escaped\\\"\"]); ?>"; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } }