diff --git a/src/wrappers/ShadowRoot.js b/src/wrappers/ShadowRoot.js index 24416b1..31ae047 100644 --- a/src/wrappers/ShadowRoot.js +++ b/src/wrappers/ShadowRoot.js @@ -16,6 +16,8 @@ var shadowHostTable = new WeakMap(); var nextOlderShadowTreeTable = new WeakMap(); + var spaceCharRe = /[ \t\n\r\f]/; + function ShadowRoot(hostWrapper) { var node = unwrap(hostWrapper.impl.ownerDocument.createDocumentFragment()); DocumentFragment.call(this, node); @@ -56,7 +58,9 @@ }, getElementById: function(id) { - return this.querySelector('#' + id); + if (spaceCharRe.test(id)) + return null; + return this.querySelector('[id="' + id + '"]'); } }); diff --git a/test/js/ShadowRoot.js b/test/js/ShadowRoot.js index acb2537..85cdbc4 100644 --- a/test/js/ShadowRoot.js +++ b/test/js/ShadowRoot.js @@ -37,6 +37,26 @@ suite('ShadowRoot', function() { assert.equal(sr.getElementById('b'), b); }); + test('getElementById with a non CSS ID', function() { + var div = document.createElement('div'); + var sr = div.createShadowRoot(); + sr.innerHTML = ''; + var a = sr.firstChild; + var b = sr.lastChild; + + assert.equal(sr.getElementById(1), a); + assert.equal(sr.getElementById(2), b); + }); + + test('getElementById with a non ID', function() { + var div = document.createElement('div'); + var sr = div.createShadowRoot(); + sr.innerHTML = ''; + var a = sr.firstChild; + + assert.isNull(sr.getElementById('a b')); + }); + test('olderShadowRoot', function() { var host = document.createElement('div'); host.innerHTML = 'ab';