Просмотр исходного кода

fix sfc parser hanging on trailing ill-formatted brackets (fix vue-loader/#628)

Evan You 9 лет назад
Родитель
Сommit
a0a619f611
2 измененных файлов с 7 добавлено и 2 удалено
  1. 2 2
      src/compiler/parser/html-parser.js
  2. 5 0
      test/unit/modules/sfc/sfc-parser.spec.js

+ 2 - 2
src/compiler/parser/html-parser.js

@@ -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
     }
   }

+ 5 - 0
test/unit/modules/sfc/sfc-parser.spec.js

@@ -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')
+  })
 })