Skip to content

Commit

Permalink
Fix mixed inline/block php blade bug
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Sep 18, 2023
1 parent 9ac653d commit f587857
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected function storeVerbatimBlocks($value)
*/
protected function storePhpBlocks($value)
{
return preg_replace_callback('/(?<!@)@php(.*?)@endphp/s', function ($matches) {
return preg_replace_callback('/(?<!@)@php((?:.(?!(?<!@)@php))*?)@endphp/s', function ($matches) {
return $this->storeRawBlock("<?php{$matches[1]}?>");
}, $value);
}
Expand Down
53 changes: 53 additions & 0 deletions tests/View/Blade/BladePhpStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,59 @@ public function testPhpStatementsWithExpressionAreCompiled()
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testMixedPhpStatementsAreCompiled()
{
$string = <<<'BLADE'
@php($set = true)
@php($set = true) @php ($set = false;) @endphp
@php ($set = true) @php($set = false;)@endphp
<div>{{ $set }}</div>
@php
$set = false;
@endphp
@php (
$set = false;
)@endphp
@php(
$set = false;
)@endphp
@php (
$set = false
)
@php(
$set = false
)
@php
$set = '@@php';
@endphp
BLADE;
$expected = <<<'PHP'
<?php ($set = true); ?>
<?php ($set = true); ?> <?php ($set = false;) ?>
<?php ($set = true); ?> <?php($set = false;)?>
<div><?php echo e($set); ?></div>
<?php
$set = false;
?>
<?php (
$set = false;
)?>
<?php(
$set = false;
)?>
<?php (
$set = false
); ?>
<?php (
$set = false
); ?>
<?php
$set = '@@php';
?>
PHP;
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testStringWithParenthesisWithEndPHP()
{
$string = "@php(\$data = ['related_to' => 'issue#45388'];) {{ \$data }} @endphp";
Expand Down

0 comments on commit f587857

Please sign in to comment.