Skip to content

Commit db35444

Browse files
committed
properly handle special newline unicode chars (fix vuejs#4268)
1 parent a11ba69 commit db35444

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/compiler/codegen/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function genNode (node: ASTNode) {
279279
function genText (text: ASTText | ASTExpression): string {
280280
return text.type === 2
281281
? text.expression // no need for () because already wrapped in _s()
282-
: JSON.stringify(text.text)
282+
: transformSpecialNewlines(JSON.stringify(text.text))
283283
}
284284

285285
function genSlot (el: ASTElement): string {
@@ -306,7 +306,14 @@ function genProps (props: Array<{ name: string, value: string }>): string {
306306
let res = ''
307307
for (let i = 0; i < props.length; i++) {
308308
const prop = props[i]
309-
res += `"${prop.name}":${prop.value},`
309+
res += `"${prop.name}":${transformSpecialNewlines(prop.value)},`
310310
}
311311
return res.slice(0, -1)
312312
}
313+
314+
// #3895, #4268
315+
function transformSpecialNewlines (text: string): string {
316+
return text
317+
.replace(/\u2028/g, '\\u2028')
318+
.replace(/\u2029/g, '\\u2029')
319+
}

src/compiler/parser/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const bindRE = /^:|^v-bind:/
2424
const onRE = /^@|^v-on:/
2525
const argRE = /:(.*)$/
2626
const modifierRE = /\.[^.]+/g
27-
const specialNewlineRE = /\u2028|\u2029/g
2827

2928
const decodeHTMLCached = cached(decode)
3029

@@ -237,8 +236,6 @@ export function parse (
237236
text
238237
})
239238
} else {
240-
// #3895 special character
241-
text = text.replace(specialNewlineRE, '')
242239
currentParent.children.push({
243240
type: 3,
244241
text

0 commit comments

Comments
 (0)