From: HcySunYang Date: Thu, 25 Mar 2021 19:53:03 +0000 (+0800) Subject: fix(compiler-core): should not condense whitespace in RCDATA text mode (#3482) X-Git-Tag: v3.0.8~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4b82159e2175d27f7d1f2641d262269f981fc86;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-core): should not condense whitespace in RCDATA text mode (#3482) fix #3479 --- diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts index a93b5e0404..790123ac67 100644 --- a/packages/compiler-core/__tests__/parse.spec.ts +++ b/packages/compiler-core/__tests__/parse.spec.ts @@ -1812,6 +1812,16 @@ foo `\n foo bar ` ) }) + + it('should NOT condense whitespaces in RCDATA text mode', () => { + const ast = baseParse(``, { + getTextMode: ({ tag }) => + tag === 'textarea' ? TextModes.RCDATA : TextModes.DATA + }) + const preElement = ast.children[0] as ElementNode + expect(preElement.children).toHaveLength(1) + expect((preElement.children[0] as TextNode).content).toBe(`Text:\n foo`) + }) }) describe('Errors', () => { diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index d57ca77a03..e847d55ed5 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -205,7 +205,7 @@ function parseChildren( // Whitespace management for more efficient output // (same as v2 whitespace: 'condense') let removedWhitespace = false - if (mode !== TextModes.RAWTEXT) { + if (mode !== TextModes.RAWTEXT && mode !== TextModes.RCDATA) { for (let i = 0; i < nodes.length; i++) { const node = nodes[i] if (!context.inPre && node.type === NodeTypes.TEXT) {