Skip to content

Commit

Permalink
Revert Blade changes (#36902)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Apr 7, 2021
1 parent 91c4547 commit 5949308
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ protected function compileExtensions($value)
protected function compileStatements($value)
{
return preg_replace_callback(
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>\'(?:\\\\\'|[^\'])*\') | (?>"(?:\\\\"|[^"])*") | (?>[^()\'"]+) | (?3) )* \))?/x', function ($match) {
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', function ($match) {
return $this->compileStatement($match);
}, $value
);
Expand Down
9 changes: 9 additions & 0 deletions tests/View/Blade/BladeForeachStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,14 @@ public function testLoopContentHolderIsExtractedFromForeachStatements()
$string = '@foreach ($tasks as $task)';
$expected = '<?php $__currentLoopData = $tasks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $task): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));

$string = "@foreach(resolve('App\\\\DataProviders\\\\'.\$provider)->data() as \$key => \$value)
<input {{ \$foo ? 'bar': 'baz' }}>
@endforeach";
$expected = "<?php \$__currentLoopData = resolve('App\\\\DataProviders\\\\'.\$provider)->data(); \$__env->addLoop(\$__currentLoopData); foreach(\$__currentLoopData as \$key => \$value): \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); ?>
<input <?php echo e(\$foo ? 'bar': 'baz'); ?>>
<?php endforeach; \$__env->popLoop(); \$loop = \$__env->getLastLoop(); ?>";

$this->assertEquals($expected, $this->compiler->compileString($string));
}
}
6 changes: 4 additions & 2 deletions tests/View/Blade/BladePhpStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ public function testVerbatimAndPhpStatementsDontGetMixedUp()
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testStringWithParenthesisDataValue()
public function testStringWithParenthesisCannotBeCompiled()
{
$string = "@php(\$data = ['test' => ')'])";

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

$this->assertEquals($expected, $this->compiler->compileString($string));
$actual = "<?php (\$data = ['test' => '); ?>'])";

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

public function testStringWithEmptyStringDataValue()
Expand Down

0 comments on commit 5949308

Please sign in to comment.