0
0
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:
Tan Li Hau 2019-11-05 08:44:13 +08:00
parent 601ec45780
commit 6d8fc8646f
4 changed files with 14 additions and 4 deletions

View File

@ -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));

View File

@ -12,13 +12,15 @@ export function escape(data: string, { only_escape_at_symbol = false } = {}) {
}
const escaped = {
'"': '&quot;',
"'": '&#39;',
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
};
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) {

View File

@ -1,3 +1,8 @@
export default {
html: `<span title='"foo"'>foo</span>`
html: `
<span title='"foo"'>
foo
<span title='"bar"'>bar</span>
</span>
`
};

View File

@ -1 +1,4 @@
<span title='"foo"'>foo</span>
<span title='"foo"'>
foo
<span title='"bar"'>bar</span>
</span>