Skip to content

[fix] attribute values are incorrectly escaped during ssr #7333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2022
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
3 changes: 2 additions & 1 deletion src/runtime/internal/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ export function create_ssr_component(fn) {

export function add_attribute(name, value, boolean) {
if (value == null || (boolean && !value)) return '';
return ` ${name}${value === true && boolean_attributes.has(name) ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value)) : `"${value}"`}`}`;
const assignment = (boolean && value === true) ? '' : `="${escape_attribute_value(value.toString())}"`;
return ` ${name}${assignment}`;
}

export function add_classes(classes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div
foo="&#34;></div><script>alert(42)</script>"
></div>
foo="&#34;></div>\<script>alert(42)</script>"
bar="&#34;></div>\<script>alert(42)</script>"
></div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
export let foo = '"></div><script>alert(42)</' + 'script>';
export let foo = '"></div>\\<script>alert(42)</' + 'script>';
export let bar = { toString: () => '"></div>\\<script>alert(42)<\/script>' };
</script>

<div foo={foo}></div>
<div foo={foo} bar={bar}></div>