mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
escape html quotes
This commit is contained in:
parent
601ec45780
commit
6d8fc8646f
@ -894,7 +894,7 @@ function to_html(wrappers: Array<ElementWrapper | TextWrapper | TagWrapper>, blo
|
||||
|
||||
attr.node.chunks.forEach(chunk => {
|
||||
if (chunk.type === 'Text') {
|
||||
state.quasi.value.raw += chunk.data;
|
||||
state.quasi.value.raw += escape_html(chunk.data);
|
||||
} else {
|
||||
literal.quasis.push(state.quasi);
|
||||
literal.expressions.push(chunk.manipulate(block));
|
||||
|
@ -12,13 +12,15 @@ export function escape(data: string, { only_escape_at_symbol = false } = {}) {
|
||||
}
|
||||
|
||||
const escaped = {
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
};
|
||||
|
||||
export function escape_html(html) {
|
||||
return String(html).replace(/[&<>]/g, match => escaped[match]);
|
||||
return String(html).replace(/["'&<>]/g, match => escaped[match]);
|
||||
}
|
||||
|
||||
export function escape_template(str) {
|
||||
|
@ -1,3 +1,8 @@
|
||||
export default {
|
||||
html: `<span title='"foo"'>foo</span>`
|
||||
html: `
|
||||
<span title='"foo"'>
|
||||
foo
|
||||
<span title='"bar"'>bar</span>
|
||||
</span>
|
||||
`
|
||||
};
|
@ -1 +1,4 @@
|
||||
<span title='"foo"'>foo</span>
|
||||
<span title='"foo"'>
|
||||
foo
|
||||
<span title='"bar"'>bar</span>
|
||||
</span>
|
Loading…
Reference in New Issue
Block a user