diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index de8f626869e3..575d3950df04 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -579,7 +579,7 @@ protected function compileFor($expression) */ protected function compileForeach($expression) { - preg_match('/\( *(.*) +as *([^\)]*)/i', $expression, $matches); + preg_match('/\( *(.*) +as *([^\)]*)/is', $expression, $matches); $iteratee = trim($matches[1]); @@ -624,7 +624,7 @@ protected function compileForelse($expression) { $empty = '$__empty_'.++$this->forelseCounter; - preg_match('/\( *(.*) +as *([^\)]*)/', $expression, $matches); + preg_match('/\( *(.*) +as *([^\)]*)/is', $expression, $matches); $iteratee = trim($matches[1]); diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index fc78b2d6fb78..f824df73c13b 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -451,6 +451,24 @@ public function testForeachStatementsAreCompileWithUppercaseSyntax() $this->assertEquals($expected, $compiler->compileString($string)); } + public function testForeachStatementsAreCompileWithMultipleLine() + { + $compiler = new BladeCompiler($this->getFiles(), __DIR__); + $string = '@foreach ([ +foo, +bar, +] as $label) +test +@endforeach'; + $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $label): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); ?> +test +popLoop(); $loop = $__env->getFirstLoop(); ?>'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + public function testNestedForeachStatementsAreCompiled() { $compiler = new BladeCompiler($this->getFiles(), __DIR__); @@ -510,6 +528,44 @@ public function testForelseStatementsAreCompiled() $this->assertEquals($expected, $compiler->compileString($string)); } + public function testForelseStatementsAreCompiledWithUppercaseSyntax() + { + $compiler = new BladeCompiler($this->getFiles(), __DIR__); + $string = '@forelse ($this->getUsers() AS $user) +breeze +@empty +empty +@endforelse'; + $expected = 'getUsers(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); $__empty_1 = false; ?> +breeze +popLoop(); $loop = $__env->getFirstLoop(); if ($__empty_1): ?> +empty +'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + + public function testForelseStatementsAreCompiledWithMultipleLine() + { + $compiler = new BladeCompiler($this->getFiles(), __DIR__); + $string = '@forelse ([ +foo, +bar, +] as $label) +breeze +@empty +empty +@endforelse'; + $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $label): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); $__empty_1 = false; ?> +breeze +popLoop(); $loop = $__env->getFirstLoop(); if ($__empty_1): ?> +empty +'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + public function testNestedForelseStatementsAreCompiled() { $compiler = new BladeCompiler($this->getFiles(), __DIR__);