Skip to content

Commit

Permalink
Fixes #45424 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed Jan 3, 2023
1 parent 2b16766 commit 310430f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 20 additions & 5 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,26 @@ protected function compileExtensions($value)
*/
protected function compileStatements($value)
{
return preg_replace_callback(
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', function ($match) {
return $this->compileStatement($match);
}, $value
);
preg_match_all('/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $value, $matches);
for ($i = 0; isset($matches[0][$i]); $i++) {
$match = [
$matches[0][$i],
$matches[1][$i],
$matches[2][$i],
$matches[3][$i] ?: null,
$matches[4][$i] ?: null,
];
while (isset($match[4]) && Str::endsWith($match[0], ')') && Arr::last(token_get_all('<?php '.$match[0])) !== ')') {
$rest = Str::before(Str::after($value, $match[0]), ')');
$match[0] = $match[0].$rest.')';
$match[3] = $match[3].$rest.')';
$match[4] = $match[4].$rest;
}

$value = str_replace($match[0], $this->compileStatement($match), $value);
}

return $value;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/View/Blade/BladePhpStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function testStringWithParenthesisCannotBeCompiled()

$expected = "<?php (\$data = ['test' => ')']); ?>";

$actual = "<?php (\$data = ['test' => '); ?>'])";
$actual = "<?php (\$data = ['test' => '); ']) ?>";

$this->assertEquals($actual, $this->compiler->compileString($string));
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testStringWithEmptyStringDataValue()
Expand Down

0 comments on commit 310430f

Please sign in to comment.