Skip to content

Commit

Permalink
fix(compile): properly generate comments with special character (#6156)
Browse files Browse the repository at this point in the history
close #6150
  • Loading branch information
gebilaoxiong authored and yyx990803 committed Jul 19, 2017
1 parent b0f00e3 commit d03fa26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export function genText (text: ASTText | ASTExpression): string {
}

export function genComment (comment: ASTText): string {
return `_e('${comment.text}')`
return `_e(${JSON.stringify(comment.text)})`
}

function genSlot (el: ASTElement, state: CodegenState): string {
Expand Down
16 changes: 15 additions & 1 deletion test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,21 @@ describe('codegen', () => {
comments: true
}, baseOptions)
const template = '<div><!--comment--></div>'
const generatedCode = `with(this){return _c('div',[_e('comment')])}`
const generatedCode = `with(this){return _c('div',[_e("comment")])}`

const ast = parse(template, options)
optimize(ast, options)
const res = generate(ast, options)
expect(res.render).toBe(generatedCode)
})

// #6150
it('generate comments with special characters', () => {
const options = extend({
comments: true
}, baseOptions)
const template = '<div><!--\n\'comment\'\n--></div>'
const generatedCode = `with(this){return _c('div',[_e("\\n'comment'\\n")])}`

const ast = parse(template, options)
optimize(ast, options)
Expand Down

0 comments on commit d03fa26

Please sign in to comment.