Skip to content

Commit 2427cec

Browse files
authored
fix single line @php statements to not be parsed as php blocks when @endphp is also in the same file, + unit test, fixes #45330 (#45333)
1 parent ab5cddb commit 2427cec

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Illuminate/View/Compilers/BladeCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ protected function storeVerbatimBlocks($value)
380380
*/
381381
protected function storePhpBlocks($value)
382382
{
383-
return preg_replace_callback('/(?<!@)@php(.*?)@endphp/s', function ($matches) {
383+
return preg_replace_callback('/(?<!@)@php(?! ?\()(.*?)@endphp/s', function ($matches) {
384384
return $this->storeRawBlock("<?php{$matches[1]}?>");
385385
}, $value);
386386
}

tests/View/Blade/BladePhpStatementsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,11 @@ public function testStringWithEscapingDataValue()
8484

8585
$this->assertEquals($expected, $this->compiler->compileString($string));
8686
}
87+
88+
public function testCompilationOfMixedPhpStatements()
89+
{
90+
$string = '@php($set = true) @php ($hello = \'hi\') @php echo "Hello world" @endphp';
91+
$expected = '<?php ($set = true); ?> <?php ($hello = \'hi\'); ?> <?php echo "Hello world" ?>';
92+
$this->assertEquals($expected, $this->compiler->compileString($string));
93+
}
8794
}

0 commit comments

Comments
 (0)