Skip to content

Commit be783c5

Browse files
efeskucukConduitry
authored andcommitted
do not collapse whitespace containing nbsp (#3014)
1 parent ac18505 commit be783c5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/compiler/compile/nodes/Text.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class Text extends Node {
1212
super(component, parent, scope, info);
1313
this.data = info.data;
1414

15-
if (!component.component_options.preserveWhitespace && !/\S/.test(info.data)) {
15+
if (!component.component_options.preserveWhitespace && !/[\S\u00A0]/.test(info.data)) {
1616
let node = parent;
1717
while (node) {
1818
if (node.type === 'Element' && node.name === 'pre') {
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
html: `<div>&nbsp;hello</div>
3+
<div>&nbsp;hello&nbsp;&nbsp;</div>
4+
<div>&nbsp;hello&nbsp; &nbsp;hello</div>`,
5+
6+
test({ assert, component, target }) {
7+
var divList = target.querySelectorAll('div')
8+
assert.equal( divList[0].textContent.charCodeAt( 0 ), 160 );
9+
assert.equal( divList[1].textContent.charCodeAt( 0 ), 160 );
10+
assert.equal( divList[1].textContent.charCodeAt( 6 ), 160 );
11+
assert.equal( divList[1].textContent.charCodeAt( 7 ), 160 );
12+
assert.equal( divList[2].textContent.charCodeAt( 0 ), 160 );
13+
assert.equal( divList[2].textContent.charCodeAt( 6 ), 160 );
14+
assert.equal( divList[2].textContent.charCodeAt( 7 ), 32 );//normal space
15+
assert.equal( divList[2].textContent.charCodeAt( 8 ), 160 );
16+
17+
18+
}
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let name = 'hello';
3+
</script>
4+
5+
<div>&nbsp;{name}</div>
6+
<div>&nbsp;{name}&nbsp;&nbsp;</div>
7+
<div>&nbsp;{name}&nbsp; &nbsp;{name}</div>

0 commit comments

Comments
 (0)