Skip to content

Commit

Permalink
better server attribute stringification
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Dec 18, 2024
1 parent 7c629e8 commit eb7a516
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions packages/svelte/src/internal/server/blocks/svelte-html.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @import { Payload } from '#server' */

import { escape_html } from '../../../escaping.js';
import { svelte_html_duplicate_attribute } from '../../shared/warnings.js';

/**
Expand All @@ -14,12 +13,12 @@ export function svelte_html(payload, attributes) {
if (payload.htmlAttributes.has(name)) {
if (name === 'class') {
// 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 {
svelte_html_duplicate_attribute(name);
}
}

payload.htmlAttributes.set(name, escape_html(value, true));
payload.htmlAttributes.set(name, value);
}
}
5 changes: 3 additions & 2 deletions packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export function render(component, options = {}) {
html: payload.out,
body: payload.out,
htmlAttributes: [...payload.htmlAttributes]
.map(([name, value]) => `${name}="${value}"`)
.join(' ')
.map(([name, value]) => attr(name, value, is_boolean_attribute(name)))
.join('')
.trim()
};
}

Expand Down

0 comments on commit eb7a516

Please sign in to comment.