Explorar o código

fix html parser infinite loop (fix #4127)

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
53964dbad2
Modificáronse 1 ficheiros con 7 adicións e 4 borrados
  1. 7 4
      src/compiler/parser/html-parser.js

+ 7 - 4
src/compiler/parser/html-parser.js

@@ -139,7 +139,7 @@ export function parseHTML (html, options) {
         }
       }
 
-      let text, rest
+      let text, rest, next
       if (textEnd > 0) {
         rest = html.slice(textEnd)
         while (
@@ -149,7 +149,9 @@ export function parseHTML (html, options) {
           !conditionalComment.test(rest)
         ) {
           // < in plain text, be forgiving and treat it as text
-          textEnd += rest.indexOf('<', 1)
+          next = rest.indexOf('<', 1)
+          if (next < 0) break
+          textEnd += next
           rest = html.slice(textEnd)
         }
         text = html.substring(0, textEnd)
@@ -185,8 +187,9 @@ export function parseHTML (html, options) {
       parseEndTag('</' + stackedTag + '>', stackedTag, index - endTagLength, index)
     }
 
-    if (html === last) {
-      throw new Error('Error parsing template:\n\n' + html)
+    if (html === last && options.chars) {
+      options.chars(html)
+      break
     }
   }