-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] Fix blade failing to compile when mixing inline/block @php directives #48420
Conversation
58e23ae
to
4b722c5
Compare
Not sure why the test is failing, everything passed when I first created this PR and the only thing I changed was adding some more cases to the test... |
Looks like they are failing on PHP 8.3. They are not failing on PHP 8.3 for other framework PRs that are open at the moment. |
Could you mark as ready for review again once tests are passing? |
@taylorotwell, tests are passing after rebase |
The additional tests suggested by @crynobone do not pass: 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));
}
public function testCompilationOfMixedUsageStatements()
{
$string = '@php (
$classes = [
\'admin-font-mono\', // Font weight
])
@endphp';
$expected = '<?php (
$classes = [
\'admin-font-mono\', // Font weight
])
?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}
public function testMultilinePhpStatementsWithParenthesesCanBeCompiled()
{
$string = "@php ("
."\n \$classes = ["
."\n 'admin-font-mono'"
."\n ])"
."\n@endphp"
."\n"
."\n<span class=\"{{ implode(' ', \$classes) }}\">Laravel</span>";
$expected = "<?php (\n"
." \$classes = [\n"
." 'admin-font-mono'\n"
." ])\n"
."?>\n"
."\n"
."<span class=\"<?php echo implode(' ', \$classes); ?>\">Laravel</span>";
$this->assertEquals($expected, $this->compiler->compileString($string));
}
public function testMixedOfPhpStatementsCanBeCompiled()
{
$string = "@php(\$total = 0)"
."\n{{-- ... --}}"
."\n<div>{{ \$total }}</div>"
."\n@php"
."\n // ..."
."\n@endphp";
$expected = "<?php (\$total = 0); ?>\n"
."\n"
."<div><?php echo e(\$total); ?></div>\n"
."<?php\n"
." // ...\n"
."?>";
$this->assertEquals($expected, $this->compiler->compileString($string));
} |
@calebdw please mark as ready for review again when tests are addressed |
There was a mistake in the third test (should be |
Thanks - will give this a shot. |
I have faced an issue today, after updating Laravel from 10.24.0 to 10.25.0 by this change. Works: Does not work anymore: It works again if you end the line with @endphp But that should not be mandatory. |
Hi, |
Chiming in here as I've had trouble upgrading to the latest version and I suspect this may be the culprit. Curiously my tests pass locally but they fail in CI (GitHub Actions) and I can't narrow down why.
I ended up removing Volt and then my tests passed in CI again. I deployed to production and then some customers complained about receiving blank pages and I was able to replicate. Rolled back to 10.24.0 and the problem has gone away. |
This has caused massive issues, and unfortunately I didn't check my app's checkout page when I did the upgrade. Prime example of how tests give you a false sense of security. Can confirm this breaks |
@taylorotwell Maybe revert this commit in a next minor release? As it causes more issues then solving. |
@jorisleermakers, @QuentinGab, @dwightwatson @mikescola, @driesvints. Additional information is needed along with a minimum reproducible example---I added tests for the specific use cases above and they pass regardless of the old or new regex. I'm specifically interested in if there are any |
We're reverting this and removing |
I understand that, but I did not succeeded to reproduce the problem with only a simple blade view and inline php. |
Closes #48407
Updated the php regex from
.*?
to(?:.(?!(?<!@)@php))*?
---long story short this is just a negative lookahead that matches everything that is not followed by@php
while also allowing@@pphp
.Partial credit goes to @rikvdh