Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit c22c0c4

Browse files
committed
Merge pull request #314 from webcomponents/create-lowercase-extend
Make sure createElement normalizes input when checking custom element defintions
2 parents 16a2149 + 5a63c09 commit c22c0c4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/CustomElements/register.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ function createElementNS(namespace, tag, typeExtension) {
268268
function createElement(tag, typeExtension) {
269269
// TODO(sjmiles): ignore 'tag' when using 'typeExtension', we could
270270
// error check it, or perhaps there should only ever be one argument
271+
if (tag) {
272+
tag = tag.toLowerCase();
273+
}
274+
if (typeExtension) {
275+
typeExtension = typeExtension.toLowerCase();
276+
}
271277
var definition = getRegisteredDefinition(typeExtension || tag);
272278
if (definition) {
273279
if (tag == definition.tag && typeExtension == definition.is) {

tests/CustomElements/js/customElements.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ suite('customElements', function() {
179179
assert.equal(xbarbarbar.textContent, 'x-barbarbar');
180180
});
181181

182+
test('document.registerElement with type extension treats names as case insensitive', function() {
183+
var proto = {prototype: Object.create(HTMLButtonElement.prototype), extends: 'button'};
184+
proto.prototype.isXCase = true;
185+
var XCase = document.registerElement('X-EXTEND-CASE', proto);
186+
// createElement
187+
var x = document.createElement('button', 'X-EXTEND-CASE');
188+
assert.equal(x.isXCase, true);
189+
x = document.createElement('button', 'x-extend-case');
190+
assert.equal(x.isXCase, true);
191+
x = document.createElement('BUTTON', 'X-EXTEND-CASE');
192+
assert.equal(x.isXCase, true);
193+
x = document.createElement('BUTTON', 'x-extend-case');
194+
assert.equal(x.isXCase, true);
195+
// upgrade
196+
work.innerHTML = '<button is="X-EXTEND-CASE"></button><button is="x-ExTeNd-CaSe"></button>';
197+
CustomElements.takeRecords();
198+
assert.equal(work.firstChild.isXCase, true);
199+
assert.equal(work.firstChild.nextSibling.isXCase, true);
200+
});
201+
182202
test('document.registerElement createdCallback in prototype', function() {
183203
var XBooPrototype = Object.create(HTMLElement.prototype);
184204
XBooPrototype.createdCallback = function() {

0 commit comments

Comments
 (0)