Skip to content

Commit

Permalink
Fix var overwriting in loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
milo committed May 23, 2022
1 parent ceed5b0 commit 91ec679
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/EmbeddedSvg/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ public function getTags(): array
return new Latte\Compiler\Nodes\AuxiliaryNode(function (Latte\Compiler\PrintContext $context) use ($macroArguments, $svgAttributes, $inner) {
return $context->format('
echo "<svg";
foreach (%0.args + %1.dump as $n => $v) {
if ($v === null || $v === false) {
foreach (%0.args + %1.dump as $__n => $__v) {
if ($__v === null || $__v === false) {
continue;
} elseif ($v === true) {
echo " " . %escape($n);
} elseif ($__v === true) {
echo " " . %escape($__n);
} else {
echo " " . %escape($n) . "=\"" . %escape($v) . "\"";
echo " " . %escape($__n) . "=\"" . %escape($__v) . "\"";
}
}
unset($__n, $__v);
echo ">" . %2.dump . "</svg>";
', [$macroArguments], $this->setting->defaultAttributes + $svgAttributes, $inner
);
Expand Down
11 changes: 6 additions & 5 deletions src/EmbeddedSvg/Macro.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ public function open(MacroNode $node, PhpWriter $writer)

return $writer->write('
echo "<svg";
foreach (%0.raw + %1.var as $n => $v) {
if ($v === null || $v === false) {
foreach (%0.raw + %1.var as $__n => $__v) {
if ($__v === null || $__v === false) {
continue;
} elseif ($v === true) {
echo " " . %escape($n);
} elseif ($__v === true) {
echo " " . %escape($__n);
} else {
echo " " . %escape($n) . "=\"" . %escape($v) . "\"";
echo " " . %escape($__n) . "=\"" . %escape($__v) . "\"";
}
}
unset($__n, $__v);
echo ">" . %2.var . "</svg>";
',
$macroAttributes, $this->setting->defaultAttributes + $svgAttributes, $inner
Expand Down

0 comments on commit 91ec679

Please sign in to comment.