Skip to content

Commit

Permalink
Fixes blade escaped tags issue
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed Feb 2, 2023
1 parent efcf3a6 commit 41e2573
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Expand Up @@ -507,6 +507,7 @@ protected function compileStatements($template)
{
preg_match_all('/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( [\S\s]*? ) \))?/x', $template, $matches);

$offset = 0;
for ($i = 0; isset($matches[0][$i]); $i++) {
$match = [
$matches[0][$i],
Expand Down Expand Up @@ -538,12 +539,35 @@ protected function compileStatements($template)
$match[4] = $match[4].$rest;
}

$template = Str::replaceFirst($match[0], $this->compileStatement($match), $template);
dump($this->compileStatement($match));
[$template, $offset] = $this->replaceFirst(
$match[0],
$this->compileStatement($match),
$template,
$offset
);
}

return $template;
}

public function replaceFirst($search, $replace, $subject, $offset)
{
$search = (string) $search;

if ($search === '') {
return $subject;
}

$position = strpos($subject, $search, $offset);

if ($position !== false) {
return [substr_replace($subject, $replace, $position, strlen($search)), $position + strlen($search) - 1];
}

return [$subject, 0];
}

/**
* Determine if the given expression has the same number of opening and closing parentheses.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/View/Blade/BladeEscapedTest.php
Expand Up @@ -16,4 +16,19 @@ public function testEscapedWithAtDirectivesAreCompiled()
$i as $x
)'));
}

public function testNestedEscapes()
{
$template = '
@foreach($cols as $col)
@@foreach($issues as $issue_45915)
@@endforeach
@endforeach';
$compiled = '
<?php $__currentLoopData = $cols; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $col): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
@foreach($issues as $issue_45915)
@endforeach
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>';
$this->assertSame($compiled, $this->compiler->compileString($template));
}
}

0 comments on commit 41e2573

Please sign in to comment.