Skip to content

Commit

Permalink
fix single line @php statements to not be parsed as php blocks when @…
Browse files Browse the repository at this point in the history
…endphp is also in the same file, + unit test, fixes #45330 (#45333)
  • Loading branch information
rikvdh committed Dec 15, 2022
1 parent ab5cddb commit 2427cec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Expand Up @@ -380,7 +380,7 @@ protected function storeVerbatimBlocks($value)
*/
protected function storePhpBlocks($value)
{
return preg_replace_callback('/(?<!@)@php(.*?)@endphp/s', function ($matches) {
return preg_replace_callback('/(?<!@)@php(?! ?\()(.*?)@endphp/s', function ($matches) {
return $this->storeRawBlock("<?php{$matches[1]}?>");
}, $value);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/View/Blade/BladePhpStatementsTest.php
Expand Up @@ -84,4 +84,11 @@ public function testStringWithEscapingDataValue()

$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testCompilationOfMixedPhpStatements()
{
$string = '@php($set = true) @php ($hello = \'hi\') @php echo "Hello world" @endphp';
$expected = '<?php ($set = true); ?> <?php ($hello = \'hi\'); ?> <?php echo "Hello world" ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}
}

0 comments on commit 2427cec

Please sign in to comment.