فهرست منبع

properly handle special newline unicode chars (fix #4268)

Evan You 9 سال پیش
والد
کامیت
db35444331
2فایلهای تغییر یافته به همراه9 افزوده شده و 5 حذف شده
  1. 9 2
      src/compiler/codegen/index.js
  2. 0 3
      src/compiler/parser/index.js

+ 9 - 2
src/compiler/codegen/index.js

@@ -279,7 +279,7 @@ function genNode (node: ASTNode) {
 function genText (text: ASTText | ASTExpression): string {
 function genText (text: ASTText | ASTExpression): string {
   return text.type === 2
   return text.type === 2
     ? text.expression // no need for () because already wrapped in _s()
     ? text.expression // no need for () because already wrapped in _s()
-    : JSON.stringify(text.text)
+    : transformSpecialNewlines(JSON.stringify(text.text))
 }
 }
 
 
 function genSlot (el: ASTElement): string {
 function genSlot (el: ASTElement): string {
@@ -306,7 +306,14 @@ function genProps (props: Array<{ name: string, value: string }>): string {
   let res = ''
   let res = ''
   for (let i = 0; i < props.length; i++) {
   for (let i = 0; i < props.length; i++) {
     const prop = props[i]
     const prop = props[i]
-    res += `"${prop.name}":${prop.value},`
+    res += `"${prop.name}":${transformSpecialNewlines(prop.value)},`
   }
   }
   return res.slice(0, -1)
   return res.slice(0, -1)
 }
 }
+
+// #3895, #4268
+function transformSpecialNewlines (text: string): string {
+  return text
+    .replace(/\u2028/g, '\\u2028')
+    .replace(/\u2029/g, '\\u2029')
+}

+ 0 - 3
src/compiler/parser/index.js

@@ -24,7 +24,6 @@ const bindRE = /^:|^v-bind:/
 const onRE = /^@|^v-on:/
 const onRE = /^@|^v-on:/
 const argRE = /:(.*)$/
 const argRE = /:(.*)$/
 const modifierRE = /\.[^.]+/g
 const modifierRE = /\.[^.]+/g
-const specialNewlineRE = /\u2028|\u2029/g
 
 
 const decodeHTMLCached = cached(decode)
 const decodeHTMLCached = cached(decode)
 
 
@@ -237,8 +236,6 @@ export function parse (
             text
             text
           })
           })
         } else {
         } else {
-          // #3895 special character
-          text = text.replace(specialNewlineRE, '')
           currentParent.children.push({
           currentParent.children.push({
             type: 3,
             type: 3,
             text
             text