From 131b3b32bdb81e469e0ad1a49bd0c3972eb51c15 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Thu, 15 Dec 2022 16:48:57 +0100 Subject: [PATCH] fix single line @php statements to not be parsed as php blocks when @endphp is also in the same file, + unit test, fixes #45330 --- src/Illuminate/View/Compilers/BladeCompiler.php | 2 +- tests/View/Blade/BladePhpStatementsTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 21f70b35a7a3..51b5abd69c5a 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -380,7 +380,7 @@ protected function storeVerbatimBlocks($value) */ protected function storePhpBlocks($value) { - return preg_replace_callback('/(?storeRawBlock(""); }, $value); } diff --git a/tests/View/Blade/BladePhpStatementsTest.php b/tests/View/Blade/BladePhpStatementsTest.php index 8f7a9f707965..131a2686dbc2 100644 --- a/tests/View/Blade/BladePhpStatementsTest.php +++ b/tests/View/Blade/BladePhpStatementsTest.php @@ -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 = ' '; + $this->assertEquals($expected, $this->compiler->compileString($string)); + } }