Skip to content

Commit 140a6f1

Browse files
committed
Fix infinite loop in blade compiler
1 parent 247735e commit 140a6f1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Illuminate/View/Compilers/BladeCompiler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,8 +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+
}
525527

528+
$rest = Str::before($after, ')');
526529
if (isset($matches[0][$i + 1]) && Str::contains($rest.')', $matches[0][$i + 1])) {
527530
unset($matches[0][$i + 1]);
528531
$i++;

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)