Skip to content

Fix div nbsp #3024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Text extends Node {
super(component, parent, scope, info);
this.data = info.data;

if (!component.component_options.preserveWhitespace && !/\S/.test(info.data)) {
if (!component.component_options.preserveWhitespace && !/[\S\u00A0]/.test(info.data)) {
let node = parent;
while (node) {
if (node.type === 'Element' && node.name === 'pre') {
Expand Down
19 changes: 19 additions & 0 deletions test/runtime/samples/nbsp-div/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
html: `<div>&nbsp;hello</div>
<div>&nbsp;hello&nbsp;&nbsp;</div>
<div>&nbsp;hello&nbsp; &nbsp;hello</div>`,

test({ assert, component, target }) {
var divList = target.querySelectorAll('div')
assert.equal( divList[0].textContent.charCodeAt( 0 ), 160 );
assert.equal( divList[1].textContent.charCodeAt( 0 ), 160 );
assert.equal( divList[1].textContent.charCodeAt( 6 ), 160 );
assert.equal( divList[1].textContent.charCodeAt( 7 ), 160 );
assert.equal( divList[2].textContent.charCodeAt( 0 ), 160 );
assert.equal( divList[2].textContent.charCodeAt( 6 ), 160 );
assert.equal( divList[2].textContent.charCodeAt( 7 ), 32 );//normal space
assert.equal( divList[2].textContent.charCodeAt( 8 ), 160 );


}
};
7 changes: 7 additions & 0 deletions test/runtime/samples/nbsp-div/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let name = 'hello';
</script>

<div>&nbsp;{name}</div>
<div>&nbsp;{name}&nbsp;&nbsp;</div>
<div>&nbsp;{name}&nbsp; &nbsp;{name}</div>