From 55a30cf9db247eba2aca817439fdb3cd15e9184f Mon Sep 17 00:00:00 2001 From: Des Preston Date: Tue, 30 Mar 2021 05:03:03 -0400 Subject: [PATCH] fix(compiler): avoid converting &nbps; to spaces (#11065) --- src/compiler/parser/index.js | 2 +- test/unit/modules/compiler/parser.spec.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 342d04ff864..d727f8dd4d1 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -38,7 +38,7 @@ const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g const slotRE = /^v-slot(:|$)|^#/ const lineBreakRE = /[\r\n]/ -const whitespaceRE = /\s+/g +const whitespaceRE = /[ \f\t\r\n]+/g const invalidAttributeRE = /[\s"'<>\/=]/ diff --git a/test/unit/modules/compiler/parser.spec.js b/test/unit/modules/compiler/parser.spec.js index 360bc11bbb6..c0b01e45364 100644 --- a/test/unit/modules/compiler/parser.spec.js +++ b/test/unit/modules/compiler/parser.spec.js @@ -865,6 +865,14 @@ describe('parser', () => { expect(ast.children[4].children[0].text).toBe('. Have fun! ') }) + it(`maintains   with whitespace: 'condense'`, () => { + const options = extend({}, condenseOptions) + const ast = parse(' ', options) + const code = ast.children[0] + expect(code.type).toBe(3) + expect(code.text).toBe('\xA0') + }) + it(`preserve whitespace in
 tag with whitespace: 'condense'`, function () {
     const options = extend({}, condenseOptions)
     const ast = parse('
  \nhi\n   
', options)