From cd06afd886c548b7b85ca2a6e62c0dbff26de1ee Mon Sep 17 00:00:00 2001 From: "wh05.park" Date: Thu, 18 Jun 2020 12:37:43 +0900 Subject: [PATCH] fix(compiler/parser/html-parser.js): Line breaks in textareas are not removed.(fix: #11446) --- src/compiler/parser/html-parser.js | 2 +- test/unit/modules/compiler/parser.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/parser/html-parser.js b/src/compiler/parser/html-parser.js index dbc59146331..6bcc3a04dbf 100644 --- a/src/compiler/parser/html-parser.js +++ b/src/compiler/parser/html-parser.js @@ -44,7 +44,7 @@ const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g // #5992 const isIgnoreNewlineTag = makeMap('pre,textarea', true) -const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n' +const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n' && html[1] && html[1] !== '\n' function decodeAttr (value, shouldDecodeNewlines) { const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr diff --git a/test/unit/modules/compiler/parser.spec.js b/test/unit/modules/compiler/parser.spec.js index d6521bbf625..e9999cbd7b5 100644 --- a/test/unit/modules/compiler/parser.spec.js +++ b/test/unit/modules/compiler/parser.spec.js @@ -698,7 +698,7 @@ describe('parser', () => { expect(text.text).toBe('\ndef') const pre2 = ast.children[2] expect(pre2.children[0].type).toBe(3) - expect(pre2.children[0].text).toBe('\nabc') + expect(pre2.children[0].text).toBe('\n\nabc') }) it('keep first newline after unary tag in
', () => {
@@ -870,7 +870,7 @@ describe('parser', () => {
     expect(text.text).toBe(' def')
     const pre2 = ast.children[2]
     expect(pre2.children[0].type).toBe(3)
-    expect(pre2.children[0].text).toBe('\nabc')
+    expect(pre2.children[0].text).toBe('\n\nabc')
   })
 
   it(`keep first newline after unary tag in 
 with whitespace: 'condense'`, () => {