better server attribute stringification

svelte-html
Simon Holthausen 9 months ago
parent 7c629e8988
commit eb7a516770

@ -1,6 +1,5 @@
/** @import { Payload } from '#server' */ /** @import { Payload } from '#server' */
import { escape_html } from '../../../escaping.js';
import { svelte_html_duplicate_attribute } from '../../shared/warnings.js'; import { svelte_html_duplicate_attribute } from '../../shared/warnings.js';
/** /**
@ -14,12 +13,12 @@ export function svelte_html(payload, attributes) {
if (payload.htmlAttributes.has(name)) { if (payload.htmlAttributes.has(name)) {
if (name === 'class') { if (name === 'class') {
// Don't bother deduplicating class names, the browser handles it just fine // Don't bother deduplicating class names, the browser handles it just fine
value = `${payload.htmlAttributes.get(name)} ${value}`; value = `${payload.htmlAttributes.get(name)} ${value}`.trim();
} else { } else {
svelte_html_duplicate_attribute(name); svelte_html_duplicate_attribute(name);
} }
} }
payload.htmlAttributes.set(name, escape_html(value, true)); payload.htmlAttributes.set(name, value);
} }
} }

@ -143,8 +143,9 @@ export function render(component, options = {}) {
html: payload.out, html: payload.out,
body: payload.out, body: payload.out,
htmlAttributes: [...payload.htmlAttributes] htmlAttributes: [...payload.htmlAttributes]
.map(([name, value]) => `${name}="${value}"`) .map(([name, value]) => attr(name, value, is_boolean_attribute(name)))
.join(' ') .join('')
.trim()
}; };
} }

Loading…
Cancel
Save