Skip to content

Commit

Permalink
fix sfc parser hanging on trailing ill-formatted brackets (fix vue-lo…
Browse files Browse the repository at this point in the history
…ader/#628)
  • Loading branch information
yyx990803 committed Feb 6, 2017
1 parent bf1f5f1 commit a0a619f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compiler/parser/html-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export function parseHTML (html, options) {
parseEndTag(stackedTag, index - endTagLength, index)
}

if (html === last && options.chars) {
options.chars(html)
if (html === last) {
options.chars && options.chars(html)
break
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit/modules/sfc/sfc-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ describe('Single File Component parser', () => {
const res = parseComponent(`<template>${raw}</template>`)
expect(res.template.content.trim()).toBe(raw)
})

it('should not hang on trailing text', () => {
const res = parseComponent(`<template>hi</`)
expect(res.template.content).toBe('hi')

This comment has been minimized.

Copy link
@defcc

defcc Feb 7, 2017

Member

Maybe we should report a parse error for this case during the compilation phase? And we could make an improvement for the parser to report the detailed error ( e.g., line number, error message and code snippet )

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Feb 7, 2017

Author Member

Yeah it's warned here for component templates: cfb4d7c

But SFC parser currently doesn't report any warnings. There's definitely room for improvement.

This comment has been minimized.

Copy link
@defcc

defcc Feb 7, 2017

Member

Got it. I'll add a note in the roadmap to record it.

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Feb 7, 2017

Author Member

Btw, the reason why I haven't tried to add line numbers etc. to the parser is mostly code-size concern because the entire parser would be shipped in the standalone build. But maybe we can use conditional compilations (like the process.env check) to keep/remove the extra parts for browser / node builds.

})
})

0 comments on commit a0a619f

Please sign in to comment.