Browse Source

improve template parser HTML entity regex (fix #2021)

Evan You 10 years ago
parent
commit
eec2cdb04f
2 changed files with 6 additions and 1 deletions
  1. 1 1
      src/parsers/template.js
  2. 5 0
      test/unit/specs/parsers/template_spec.js

+ 1 - 1
src/parsers/template.js

@@ -71,7 +71,7 @@ function isRealTemplate (node) {
 }
 
 const tagRE = /<([\w:]+)/
-const entityRE = /&\w+;|&#\d+;|&#x[\dA-F]+;/
+const entityRE = /&#?\w+?;/
 
 /**
  * Convert a string template to a DocumentFragment.

+ 5 - 0
test/unit/specs/parsers/template_spec.js

@@ -44,6 +44,11 @@ describe('Template Parser', function () {
     expect(res instanceof DocumentFragment).toBeTruthy()
     expect(res.childNodes.length).toBe(1)
     expect(res.firstChild.nodeValue).toBe('hello / hello')
+    // #2021
+    res = parse('&#xe604;')
+    expect(res instanceof DocumentFragment).toBeTruthy()
+    expect(res.childNodes.length).toBe(1)
+    expect(res.firstChild.nodeValue).toBe('')
   })
 
   it('should parse textContent if argument is a script node', function () {