diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php index f54d33b5ffc9..591a1330b9ff 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php @@ -379,7 +379,16 @@ protected function compileSelected($condition) */ protected function compilePushIf($expression) { - $parts = explode(',', $this->stripParentheses($expression), 2); + $parts = explode(',', $this->stripParentheses($expression)); + + if (count($parts) > 2) { + $last = array_pop($parts); + + $parts = [ + implode(',', $parts), + 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\')