diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index a27d977d7b05..c94d2084b734 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -504,11 +504,26 @@ protected function compileExtensions($value) */ protected function compileStatements($value) { - return preg_replace_callback( - '/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', function ($match) { - return $this->compileStatement($match); - }, $value - ); + preg_match_all('/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $value, $matches); + for ($i = 0; isset($matches[0][$i]); $i++) { + $match = [ + $matches[0][$i], + $matches[1][$i], + $matches[2][$i], + $matches[3][$i] ?: null, + $matches[4][$i] ?: null, + ]; + while (isset($match[4]) && Str::endsWith($match[0], ')') && Arr::last(token_get_all('compileStatement($match), $value); + } + + return $value; } /** diff --git a/tests/View/Blade/BladePhpStatementsTest.php b/tests/View/Blade/BladePhpStatementsTest.php index 8f7a9f707965..5800487ee0fa 100644 --- a/tests/View/Blade/BladePhpStatementsTest.php +++ b/tests/View/Blade/BladePhpStatementsTest.php @@ -50,9 +50,9 @@ public function testStringWithParenthesisCannotBeCompiled() $expected = " ')']); ?>"; - $actual = " '); ?>'])"; + $actual = " '); ']) ?>"; - $this->assertEquals($actual, $this->compiler->compileString($string)); + $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testStringWithEmptyStringDataValue()