jsdom
jsdom copied to clipboard
selectors are case-sensitive, in violation of spec (because of a bug in a dependency)
This is due to a bug in the latest version of nwsapi, which had its first release in three years nine days ago. But it affects JSDOM because this package does not pin a version of nwsapi. You might want to pin 2.2.0 until the linked bug gets fixed.
Minimal reproduction case
let { JSDOM } = require('jsdom');
let { document } = (new JSDOM('<p>')).window;
console.log([document.querySelector('P'), document.querySelector('p')]);
// prints [ null, HTMLParagraphElement {} ]
How does similar code behave in browsers?
Selectors are not case-sensitive, so both elements of the printed array are non-null.
I encountered similar error with child selector during XML parsing (XML should be case-sensitive):
// run this in NodeJS, works OK in FF/Chrome (omit these two lines)
const { JSDOM } = require('jsdom');
const window = (new JSDOM()).window;
var parser = new window.DOMParser();
var doc = parser.parseFromString(`<elem>
<Test>
content
<my-tag>abc</my-tag>
</Test>
</elem>`, 'text/xml');
console.assert(doc.querySelectorAll('Test').length == 1, 'Test tag not found');
console.assert(doc.querySelectorAll('test').length == 0, 'test tag exists');
console.assert(doc.querySelectorAll('my-tag').length == 1, 'my-tag tag not found');
console.assert(doc.querySelectorAll('Test>my-tag').length == 1, 'Test>tag not found');