Skip to content

Commit 05fd677

Browse files
committed
AttributeNode: Removed support for URL checking, it remains in ExpressionAttributeNode
1 parent 5cac35d commit 05fd677

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/Latte/Compiler/Escaper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function enterHtmlRaw(string $subType): void
152152
}
153153

154154

155-
public function enterHtmlAttribute(?string $name = null): void
155+
public function enterHtmlAttribute(?string $name, bool $expression = false): void
156156
{
157157
$this->state = self::HtmlAttribute;
158158
$this->subType = '';
@@ -163,8 +163,8 @@ public function enterHtmlAttribute(?string $name = null): void
163163
$this->subType = self::JavaScript;
164164
} elseif ($name === 'style') {
165165
$this->subType = self::Css;
166-
} elseif ((in_array($name, ['href', 'src', 'action', 'formaction'], true)
167-
|| ($name === 'data' && strcasecmp($this->tag, 'object') === 0))
166+
} elseif ($expression && ((in_array($name, ['href', 'src', 'action', 'formaction'], true)
167+
|| ($name === 'data' && strcasecmp($this->tag, 'object') === 0)))
168168
) {
169169
$this->subType = self::Url;
170170
}

src/Latte/Compiler/Nodes/Html/AttributeNode.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Latte\Compiler\NodeHelpers;
1313
use Latte\Compiler\Nodes\AreaNode;
14-
use Latte\Compiler\Nodes\FragmentNode;
1514
use Latte\Compiler\Nodes\TextNode;
1615
use Latte\Compiler\Position;
1716
use Latte\Compiler\PrintContext;
@@ -35,23 +34,14 @@ public function print(PrintContext $context): string
3534
return $res;
3635
}
3736

38-
$res .= "echo '=';";
39-
$quote = $this->quote ?? ($this->value instanceof TextNode ? null : '"');
40-
$res .= $quote ? 'echo ' . var_export($quote, true) . ';' : '';
41-
4237
$escaper = $context->beginEscape();
4338
$escaper->enterHtmlAttribute(NodeHelpers::toText($this->name));
44-
if ($this->value instanceof FragmentNode && $escaper->export() === 'html/attr/url') {
45-
foreach ($this->value->children as $child) {
46-
$res .= $child->print($context);
47-
$escaper->enterHtmlAttribute(null);
48-
}
49-
} else {
50-
$res .= $this->value->print($context);
51-
}
52-
39+
$res .= $context->format(
40+
"echo '='; echo %dump; %node echo %0.dump;",
41+
$this->quote ?? ($this->value instanceof TextNode ? null : '"'),
42+
$this->value,
43+
);
5344
$context->restoreEscape();
54-
$res .= $quote ? 'echo ' . var_export($quote, true) . ';' : '';
5545
return $res;
5646
}
5747

src/Latte/Compiler/Nodes/Html/ExpressionAttributeNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(
3131
public function print(PrintContext $context): string
3232
{
3333
$escaper = $context->beginEscape();
34-
$escaper->enterHtmlAttribute($this->name);
34+
$escaper->enterHtmlAttribute($this->name, expression: true);
3535
$res = $context->format(
3636
'echo %3.dump; echo %modify(%node) %line; echo \'"\';',
3737
$this->modifier,

0 commit comments

Comments
 (0)