Skip to content

Commit

Permalink
[9.x] Fix infinite loop in blade compiler (#45780)
Browse files Browse the repository at this point in the history
* Fix infinite loop in blade compiler

* Update BladeCompiler.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
imanghafoori1 and taylorotwell authored Jan 24, 2023
1 parent 7f60262 commit 519831d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,11 @@ protected function compileStatements($template)
while (isset($match[4]) &&
Str::endsWith($match[0], ')') &&
! $this->hasEvenNumberOfParentheses($match[0])) {
$rest = Str::before(Str::after($template, $match[0]), ')');
if (($after = Str::after($template, $match[0])) === $template) {
break;
}

$rest = Str::before($after, ')');

if (isset($matches[0][$i + 1]) && Str::contains($rest.')', $matches[0][$i + 1])) {
unset($matches[0][$i + 1]);
Expand Down
6 changes: 6 additions & 0 deletions tests/View/Blade/BladePhpStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,10 @@ public function testNestedTagCalls()
$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>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testItDoesNotCompileInvalidSyntax()
{
$template = "<a @class(['k\' => ()])></a>";
$this->assertEquals($template, $this->compiler->compileString($template));
}
}

0 comments on commit 519831d

Please sign in to comment.