Skip to content

Commit 519831d

Browse files
[9.x] Fix infinite loop in blade compiler (#45780)
* Fix infinite loop in blade compiler * Update BladeCompiler.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 7f60262 commit 519831d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Illuminate/View/Compilers/BladeCompiler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,11 @@ protected function compileStatements($template)
521521
while (isset($match[4]) &&
522522
Str::endsWith($match[0], ')') &&
523523
! $this->hasEvenNumberOfParentheses($match[0])) {
524-
$rest = Str::before(Str::after($template, $match[0]), ')');
524+
if (($after = Str::after($template, $match[0])) === $template) {
525+
break;
526+
}
527+
528+
$rest = Str::before($after, ')');
525529

526530
if (isset($matches[0][$i + 1]) && Str::contains($rest.')', $matches[0][$i + 1])) {
527531
unset($matches[0][$i + 1]);

tests/View/Blade/BladePhpStatementsTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,10 @@ public function testNestedTagCalls()
172172
$expected = '<span class="<?php echo \Illuminate\Support\Arr::toCssClasses([\'k\' => @empty($v), \'t\' => @empty($v1), \'r\' => @empty($v2), \'l\' => \'l\']) ?>"></span><span class="<?php echo \Illuminate\Support\Arr::toCssClasses([\'k\' => @empty($v)]) ?>"></span>';
173173
$this->assertEquals($expected, $this->compiler->compileString($string));
174174
}
175+
176+
public function testItDoesNotCompileInvalidSyntax()
177+
{
178+
$template = "<a @class(['k\' => ()])></a>";
179+
$this->assertEquals($template, $this->compiler->compileString($template));
180+
}
175181
}

0 commit comments

Comments
 (0)