Skip to content

Commit 53964db

Browse files
committed
fix html parser infinite loop (fix vuejs#4127)
1 parent 51725cf commit 53964db

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/compiler/parser/html-parser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export function parseHTML (html, options) {
139139
}
140140
}
141141

142-
let text, rest
142+
let text, rest, next
143143
if (textEnd > 0) {
144144
rest = html.slice(textEnd)
145145
while (
@@ -149,7 +149,9 @@ export function parseHTML (html, options) {
149149
!conditionalComment.test(rest)
150150
) {
151151
// < in plain text, be forgiving and treat it as text
152-
textEnd += rest.indexOf('<', 1)
152+
next = rest.indexOf('<', 1)
153+
if (next < 0) break
154+
textEnd += next
153155
rest = html.slice(textEnd)
154156
}
155157
text = html.substring(0, textEnd)
@@ -185,8 +187,9 @@ export function parseHTML (html, options) {
185187
parseEndTag('</' + stackedTag + '>', stackedTag, index - endTagLength, index)
186188
}
187189

188-
if (html === last) {
189-
throw new Error('Error parsing template:\n\n' + html)
190+
if (html === last && options.chars) {
191+
options.chars(html)
192+
break
190193
}
191194
}
192195

0 commit comments

Comments
 (0)