Skip to content

Commit e15a402

Browse files
committed
fix(compiler): avoid converting &nbps; to spaces (fix vuejs#11059)
The regex for whitespace was too strict and was causing $nbps; chars to disappear from templates when `whitespace: 'condense'` is set. Changing the rule to avoid converting non-breaking white space chars into regular spaces.
1 parent ec78fc8 commit e15a402

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/compiler/parser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g
3838
const slotRE = /^v-slot(:|$)|^#/
3939

4040
const lineBreakRE = /[\r\n]/
41-
const whitespaceRE = /\s+/g
41+
const whitespaceRE = /[ \t\r\n]+/g
4242

4343
const invalidAttributeRE = /[\s"'<>\/=]/
4444

test/unit/modules/compiler/parser.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,14 @@ describe('parser', () => {
845845
expect(ast.children[4].children[0].text).toBe('. Have fun! ')
846846
})
847847

848+
it(`maintains &nbsp; with whitespace: 'condense'`, () => {
849+
const options = extend({}, condenseOptions)
850+
const ast = parse('<span>&nbsp;</span>', options)
851+
const code = ast.children[0]
852+
expect(code.type).toBe(3)
853+
expect(code.text).toBe('\xA0')
854+
})
855+
848856
it(`preserve whitespace in <pre> tag with whitespace: 'condense'`, function () {
849857
const options = extend({}, condenseOptions)
850858
const ast = parse('<pre><code> \n<span>hi</span>\n </code><span> </span></pre>', options)

0 commit comments

Comments
 (0)