From e15a40298b3a328329a9e58f34d38a5607e08534 Mon Sep 17 00:00:00 2001 From: Des Preston Date: Sun, 2 Feb 2020 11:25:29 -0500 Subject: [PATCH 1/2] fix(compiler): avoid converting &nbps; to spaces (fix #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. --- 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 4debf62a1f4..821cb462fcd 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 = /[ \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 d6521bbf625..638b3a1293d 100644 --- a/test/unit/modules/compiler/parser.spec.js +++ b/test/unit/modules/compiler/parser.spec.js @@ -845,6 +845,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) From 7fb1f9892be4d3b864b7be91e90d77140c43061c Mon Sep 17 00:00:00 2001 From: Des Preston Date: Mon, 3 Feb 2020 10:26:48 -0500 Subject: [PATCH 2/2] perf(compiler): include form-feed char as part of whitespace regex --- src/compiler/parser/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 821cb462fcd..434561f191b 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 = /[ \t\r\n]+/g +const whitespaceRE = /[ \f\t\r\n]+/g const invalidAttributeRE = /[\s"'<>\/=]/