escape html quotes

pull/3851/head
Tan Li Hau 5 years ago
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 = {
'"': '&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) {

@ -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…
Cancel
Save