File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ map.rect = [
56
56
'</svg>'
57
57
]
58
58
59
- var TAG_RE = / < ( [ \w : ] + ) /
59
+ var tagRE = / < ( [ \w : ] + ) /
60
+ var entityRE = / & \w + ; /
60
61
61
62
/**
62
63
* Convert a string template to a DocumentFragment.
@@ -75,16 +76,17 @@ function stringToFragment (templateString) {
75
76
}
76
77
77
78
var frag = document . createDocumentFragment ( )
78
- var tagMatch = TAG_RE . exec ( templateString )
79
+ var tagMatch = templateString . match ( tagRE )
80
+ var entityMatch = entityRE . test ( templateString )
79
81
80
- if ( ! tagMatch ) {
82
+ if ( ! tagMatch && ! entityMatch ) {
81
83
// text only, return a single text node.
82
84
frag . appendChild (
83
85
document . createTextNode ( templateString )
84
86
)
85
87
} else {
86
88
87
- var tag = tagMatch [ 1 ]
89
+ var tag = tagMatch && tagMatch [ 1 ]
88
90
var wrap = map [ tag ] || map . _default
89
91
var depth = wrap [ 0 ]
90
92
var prefix = wrap [ 1 ]
Original file line number Diff line number Diff line change @@ -37,6 +37,13 @@ if (_.inBrowser) {
37
37
expect ( res . firstChild . nodeType ) . toBe ( 3 ) // Text node
38
38
} )
39
39
40
+ it ( 'should handle string that contains html entities' , function ( ) {
41
+ var res = parse ( 'hi<hi' )
42
+ expect ( res instanceof DocumentFragment ) . toBeTruthy ( )
43
+ expect ( res . childNodes . length ) . toBe ( 1 )
44
+ expect ( res . firstChild . nodeValue ) . toBe ( 'hi<hi' )
45
+ } )
46
+
40
47
it ( 'should parse textContent if argument is a script node' , function ( ) {
41
48
var node = document . createElement ( 'script' )
42
49
node . textContent = testString
You can’t perform that action at this time.
0 commit comments