Skip to content

Commit

Permalink
Fix infinite loop in blade compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed Jan 24, 2023
1 parent 247735e commit 392c5f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +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]);
$i++;
Expand Down Expand Up @@ -680,7 +683,7 @@ public function if($name, callable $callback)
* Check the result of a condition.
*
* @param string $name
* @param array ...$parameters
* @param array $parameters
* @return bool
*/
public function check($name, ...$parameters)
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 392c5f4

Please sign in to comment.