Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/view/src/Attributes/ExpressionAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public static function render(string $name, mixed $value): string
return '';
}

$resolvedValue = self::resolveValue($value);
$resolvedValue = htmlspecialchars(
string: self::resolveValue($value),
flags: ENT_QUOTES | ENT_SUBSTITUTE,
encoding: 'UTF-8',
);

if ($resolvedValue === '') {
return '';
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/View/TempestViewRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,17 @@ public function test_whitespace_with_blank_lines_between_inline_elements_is_pres
<em>Test</em></p>'),
);
}

public function test_expressions_attributes_are_escaped(): void
{
$html = $this->view->render(view(
'<a :href="$v">click</a>',
v: 'x" onmouseover="alert(document.cookie)',
));

$this->assertSnippetsMatch(
'<a href="x&quot; onmouseover=&quot;alert(document.cookie)">click</a>',
$html,
);
}
}
Loading