Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cdd1227

Browse files
committed
fix(jqLite): properly handle dash-delimited node names in jqLiteBuildFragment
Fixes #10617 Closes #12759
1 parent 19ecdb5 commit cdd1227

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/jqLite.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ function camelCase(name) {
151151
replace(MOZ_HACK_REGEXP, 'Moz$1');
152152
}
153153

154-
var SINGLE_TAG_REGEXP = /^<(\w+)\s*\/?>(?:<\/\1>|)$/;
154+
var SINGLE_TAG_REGEXP = /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/;
155155
var HTML_REGEXP = /<|&#?\w+;/;
156-
var TAG_NAME_REGEXP = /<([\w:]+)/;
157-
var XHTML_TAG_REGEXP = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi;
156+
var TAG_NAME_REGEXP = /<([\w:-]+)/;
157+
var XHTML_TAG_REGEXP = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi;
158158

159159
var wrapMap = {
160160
'option': [1, '<select multiple="multiple">', '</select>'],

test/jqLiteSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ describe('jqLite', function() {
7878
});
7979

8080

81+
// This is not working correctly in jQuery prior to v3.0.
82+
// See https://github.com/jquery/jquery/issues/1987 for details.
83+
it('should properly handle dash-delimited node names', function() {
84+
var jQueryVersion = window.jQuery && window.jQuery.fn.jquery.split('.')[0];
85+
var jQuery3xOrNewer = jQueryVersion && (Number(jQueryVersion) >= 3);
86+
87+
if (_jqLiteMode || jQuery3xOrNewer) {
88+
var nodeNames = 'thead tbody tfoot colgroup caption tr th td div kung'.split(' ');
89+
var nodeNamesTested = 0;
90+
var nodes, customNodeName;
91+
92+
forEach(nodeNames, function(nodeName) {
93+
var customNodeName = nodeName + '-foo';
94+
var nodes = jqLite('<' + customNodeName + '>Hello, world !</' + customNodeName + '>');
95+
96+
expect(nodes.length).toBe(1);
97+
expect(nodeName_(nodes)).toBe(customNodeName);
98+
expect(nodes.html()).toBe('Hello, world !');
99+
100+
nodeNamesTested++;
101+
});
102+
103+
expect(nodeNamesTested).toBe(10);
104+
}
105+
});
106+
107+
81108
it('should allow creation of comment tags', function() {
82109
var nodes = jqLite('<!-- foo -->');
83110
expect(nodes.length).toBe(1);

0 commit comments

Comments
 (0)