Skip to content

Commit 8c17535

Browse files
committed
fix(compiler): should not condense  
fix #945
1 parent be666eb commit 8c17535

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/compiler-core/src/parse.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function parseChildren(
194194
for (let i = 0; i < nodes.length; i++) {
195195
const node = nodes[i]
196196
if (node.type === NodeTypes.TEXT) {
197-
if (!node.content.trim()) {
197+
if (!/[^\t\r\n\f ]/.test(node.content)) {
198198
const prev = nodes[i - 1]
199199
const next = nodes[i + 1]
200200
// If:
@@ -219,7 +219,7 @@ function parseChildren(
219219
node.content = ' '
220220
}
221221
} else {
222-
node.content = node.content.replace(/\s+/g, ' ')
222+
node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ')
223223
}
224224
}
225225
}

packages/compiler-dom/__tests__/parse.spec.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
InterpolationNode
99
} from '@vue/compiler-core'
1010
import {
11-
parserOptionsMinimal as parserOptions,
11+
parserOptionsStandard as parserOptions,
1212
DOMNamespaces
13-
} from '../src/parserOptionsMinimal'
13+
} from '../src/parserOptionsStandard'
1414

1515
describe('DOM parser', () => {
1616
describe('Text', () => {
@@ -160,6 +160,16 @@ describe('DOM parser', () => {
160160
}
161161
])
162162
})
163+
164+
// #945
165+
test('&nbsp; should not be condensed', () => {
166+
const nbsp = String.fromCharCode(160)
167+
const ast = parse(`foo&nbsp;&nbsp;bar`, parserOptions)
168+
expect(ast.children[0]).toMatchObject({
169+
type: NodeTypes.TEXT,
170+
content: `foo${nbsp}${nbsp}bar`
171+
})
172+
})
163173
})
164174

165175
describe('Interpolation', () => {

packages/compiler-dom/src/parserOptionsStandard.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ParserOptions } from '@vue/compiler-core'
22
import { parserOptionsMinimal } from './parserOptionsMinimal'
33
import namedCharacterReferences from './namedChars.json'
44

5+
export { DOMNamespaces } from './parserOptionsMinimal'
6+
57
export const parserOptionsStandard: ParserOptions = {
68
// extends the minimal options with more spec-compliant overrides
79
...parserOptionsMinimal,

0 commit comments

Comments
 (0)