]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler): should not condense  
authorEvan You <yyx990803@gmail.com>
Wed, 8 Apr 2020 21:33:07 +0000 (17:33 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 8 Apr 2020 21:33:07 +0000 (17:33 -0400)
fix #945

packages/compiler-core/src/parse.ts
packages/compiler-dom/__tests__/parse.spec.ts
packages/compiler-dom/src/parserOptionsStandard.ts

index 1fbd7d5c24d14193307872e41961f8beae9219d1..bb4e3e4a6a422ccf44f968988ec6fd1659a0c495 100644 (file)
@@ -194,7 +194,7 @@ function parseChildren(
       for (let i = 0; i < nodes.length; i++) {
         const node = nodes[i]
         if (node.type === NodeTypes.TEXT) {
-          if (!node.content.trim()) {
+          if (!/[^\t\r\n\f ]/.test(node.content)) {
             const prev = nodes[i - 1]
             const next = nodes[i + 1]
             // If:
@@ -219,7 +219,7 @@ function parseChildren(
               node.content = ' '
             }
           } else {
-            node.content = node.content.replace(/\s+/g, ' ')
+            node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ')
           }
         }
       }
index 8e88d14954c3cc70d387b5ce590644552183ade6..73a27e205d5fa813b7ebdf76e9072a7287901ad6 100644 (file)
@@ -8,9 +8,9 @@ import {
   InterpolationNode
 } from '@vue/compiler-core'
 import {
-  parserOptionsMinimal as parserOptions,
+  parserOptionsStandard as parserOptions,
   DOMNamespaces
-} from '../src/parserOptionsMinimal'
+} from '../src/parserOptionsStandard'
 
 describe('DOM parser', () => {
   describe('Text', () => {
@@ -160,6 +160,16 @@ describe('DOM parser', () => {
         }
       ])
     })
+
+    // #945
+    test('&nbsp; should not be condensed', () => {
+      const nbsp = String.fromCharCode(160)
+      const ast = parse(`foo&nbsp;&nbsp;bar`, parserOptions)
+      expect(ast.children[0]).toMatchObject({
+        type: NodeTypes.TEXT,
+        content: `foo${nbsp}${nbsp}bar`
+      })
+    })
   })
 
   describe('Interpolation', () => {
index 0fe9bfded0a45de27061f460bc559f74c569571d..b0bb70e4e997aa1427741c1a326837792d8b69ed 100644 (file)
@@ -2,6 +2,8 @@ import { ParserOptions } from '@vue/compiler-core'
 import { parserOptionsMinimal } from './parserOptionsMinimal'
 import namedCharacterReferences from './namedChars.json'
 
+export { DOMNamespaces } from './parserOptionsMinimal'
+
 export const parserOptionsStandard: ParserOptions = {
   // extends the minimal options with more spec-compliant overrides
   ...parserOptionsMinimal,