Skip to content

Commit eec2cdb

Browse files
committed
improve template parser HTML entity regex (fix vuejs#2021)
1 parent afc15aa commit eec2cdb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/parsers/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function isRealTemplate (node) {
7171
}
7272

7373
const tagRE = /<([\w:]+)/
74-
const entityRE = /&\w+;|&#\d+;|&#x[\dA-F]+;/
74+
const entityRE = /&#?\w+?;/
7575

7676
/**
7777
* Convert a string template to a DocumentFragment.

test/unit/specs/parsers/template_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ describe('Template Parser', function () {
4444
expect(res instanceof DocumentFragment).toBeTruthy()
4545
expect(res.childNodes.length).toBe(1)
4646
expect(res.firstChild.nodeValue).toBe('hello / hello')
47+
// #2021
48+
res = parse('&#xe604;')
49+
expect(res instanceof DocumentFragment).toBeTruthy()
50+
expect(res.childNodes.length).toBe(1)
51+
expect(res.firstChild.nodeValue).toBe('')
4752
})
4853

4954
it('should parse textContent if argument is a script node', function () {

0 commit comments

Comments
 (0)