Skip to content

Commit 5b1f5e5

Browse files
committed
do the escaping inside template_to_string
1 parent d9d24a2 commit 5b1f5e5

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-string.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @import { TemplateOperations } from "../types.js"
33
*/
4+
import { escape_html } from '../../../../../escaping.js';
45
import { is_void } from '../../../../../utils.js';
56

67
/**
@@ -67,7 +68,7 @@ export function template_to_string(items) {
6768
const el = /** @type {Element} */ (last_current_element);
6869
const [prop, value] = /** @type {string[]} */ (instruction.args);
6970
el.props ??= {};
70-
el.props[prop] = value;
71+
el.props[prop] = escape_html(value, true);
7172
break;
7273
}
7374
}

packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,7 @@ export function RegularElement(node, context) {
122122
if (value.type === 'Literal' && typeof value.value === 'string') {
123123
context.state.template.push({
124124
kind: 'set_prop',
125-
args: [
126-
'is',
127-
// if we are using the functional template mode we don't want to escape since we will
128-
// create a text node from it which is already escaped
129-
context.state.is_functional_template_mode
130-
? value.value
131-
: escape_html(value.value, true)
132-
]
125+
args: ['is', value.value]
133126
});
134127
continue;
135128
}
@@ -313,17 +306,7 @@ export function RegularElement(node, context) {
313306
context.state.template.push({
314307
kind: 'set_prop',
315308
args: [attribute.name].concat(
316-
is_boolean_attribute(name) && value === true
317-
? []
318-
: [
319-
value === true
320-
? ''
321-
: // if we are using the functional template mode we don't want to escape since we will
322-
// create a text node from it which is already escaped
323-
context.state.is_functional_template_mode
324-
? value
325-
: escape_html(value, true)
326-
]
309+
is_boolean_attribute(name) && value === true ? [] : [value === true ? '' : value]
327310
)
328311
});
329312
}

0 commit comments

Comments
 (0)