From 763a7ac09133c7f8728d47d43bd4fbe7c9ab8fb2 Mon Sep 17 00:00:00 2001 From: Iman Ghafoori Date: Tue, 3 Jan 2023 00:40:38 +0330 Subject: [PATCH] Fixes #45424 issue --- .../View/Compilers/BladeCompiler.php | 25 +++++++++++++++---- tests/View/Blade/BladePhpStatementsTest.php | 4 +-- 2 files changed, 22 insertions(+), 7 deletions(-) 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()