From 8032144c6f15c500768a0d08f025f31099b1b105 Mon Sep 17 00:00:00 2001 From: Hossein Hosni Date: Sat, 4 Oct 2025 18:16:34 +0330 Subject: [PATCH 1/3] [12.x] Fix using pushIf blade directive with complex conditions (#57264) --- .../Concerns/CompilesConditionals.php | 13 +++++++++- tests/View/Blade/BladePushTest.php | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php index f54d33b5ffc9..39b74a49a649 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php @@ -379,7 +379,18 @@ protected function compileSelected($condition) */ protected function compilePushIf($expression) { - $parts = explode(',', $this->stripParentheses($expression), 2); + $parts = explode(',', $this->stripParentheses($expression)); + + /** + * @see https://github.com/laravel/framework/issues/57264 + */ + if (count($parts) > 2) { + $last = array_pop($parts); + $parts = [ + 0 => implode(',', $parts), + 1 => trim($last), + ]; + } return "startPush({$parts[1]}); ?>"; } diff --git a/tests/View/Blade/BladePushTest.php b/tests/View/Blade/BladePushTest.php index 84f3d3f33bfd..0f1ce86e84e5 100644 --- a/tests/View/Blade/BladePushTest.php +++ b/tests/View/Blade/BladePushTest.php @@ -70,6 +70,32 @@ public function testPushIfIsCompiled() $this->assertEquals($expected, $this->compiler->compileString($string)); } + public function testPushIfWithMoreThanOneCommaIsCompiled() + { + $string = '@pushIf(Str::startsWith(\'abc\', \'a\'), \'body-end\') +test +@endPushIf'; + + $expected = 'startPush(\'body-end\'); ?> +test +stopPush(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testPushIfWithCommaInStringIsCompiled() + { + $string = '@pushIf(Str::startsWith(\'abc,,,\', \'a,,,\'), \'body-end\') +test +@endPushIf'; + + $expected = 'startPush(\'body-end\'); ?> +test +stopPush(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + public function testPushIfElseIsCompiled() { $string = '@pushIf(true, \'stack\') From 7a7bb8a47ba8c1fb5ae8c520cfd74b2d6f071d12 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Oct 2025 18:31:22 -0500 Subject: [PATCH 2/3] Update CompilesConditionals.php --- .../View/Compilers/Concerns/CompilesConditionals.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php index 39b74a49a649..6b9fcc2b7306 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php @@ -381,11 +381,9 @@ protected function compilePushIf($expression) { $parts = explode(',', $this->stripParentheses($expression)); - /** - * @see https://github.com/laravel/framework/issues/57264 - */ if (count($parts) > 2) { $last = array_pop($parts); + $parts = [ 0 => implode(',', $parts), 1 => trim($last), From 99dbd378be91a0fdd407672c5c7348afaf798ebb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Oct 2025 18:31:51 -0500 Subject: [PATCH 3/3] Update CompilesConditionals.php --- .../View/Compilers/Concerns/CompilesConditionals.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php index 6b9fcc2b7306..591a1330b9ff 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php @@ -385,8 +385,8 @@ protected function compilePushIf($expression) $last = array_pop($parts); $parts = [ - 0 => implode(',', $parts), - 1 => trim($last), + implode(',', $parts), + trim($last), ]; }