Skip to content

Commit 9bce3fc

Browse files
committed
fix text nodes in .innerHTML-optimized output
- collapse whitespace to single space when appropriate (#2745) - escape template string characters in script and style tags
1 parent 5e81280 commit 9bce3fc

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/compiler/compile/render-dom/wrappers/Element/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,18 @@ export default class ElementWrapper extends Wrapper {
335335

336336
function to_html(wrapper: ElementWrapper | TextWrapper) {
337337
if (wrapper.node.type === 'Text') {
338+
if (wrapper.node.use_space) return ' ';
339+
338340
const parent = wrapper.node.parent as Element;
339341

340342
const raw = parent && (
341343
parent.name === 'script' ||
342344
parent.name === 'style'
343345
);
344346

345-
return raw
347+
return (raw
346348
? wrapper.node.data
347-
: escape_html(wrapper.node.data)
349+
: escape_html(wrapper.node.data))
348350
.replace(/\\/g, '\\\\')
349351
.replace(/`/g, '\\`')
350352
.replace(/\$/g, '\\$');

test/runtime/samples/script-style-non-top-level/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
html: `
33
<div>
44
<style>div { color: red; }</style>
5-
<script>alert('<>');</script>
5+
<script>alert(\`<>\`);</script>
66
</div>
77
`
88
};
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div>
22
<style>div { color: red; }</style>
3-
<script>alert('<>');</script>
3+
<script>alert(`<>`);</script>
44
</div>

0 commit comments

Comments
 (0)