tmpvar/jsdom — Issue #393: tagName and nodeName getters overridden when parsed with jsdom.jsdom, causing various problems with XML DOM
Author: jbeard4
Created: 2012-01-31 21:14:08+00:00
State: open

There are various problems when parsing HTML using jsdom.jsdom. Here is a reduced test case:

var jsdom = require("jsdom");

var doc = jsdom.jsdom('',jsdom.dom.level3.core);

console.log(doc.documentElement); //this will be undefined
var f = doc.getElementsByTagName('foo')[0]; //getElementsByTagName still works
conosle.log(f.tagName); //this will be "FOO" instead of "foo"

Basically, document.documentElement will be undefined, and tagName and nodeName getters will always return uppercase form.

I traced the code, and found that the problem is most likely in jsdom/browser/index.js, lines 550 - 561, as tagName and nodeName get overriden:

https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/browser/index.js#L550

This will override the getters defined in jsdom.dom.level1.core module, which will return lowercase form for non-HTML documents.

Deleting lines 550 - 561 seems to fix both of these problems: document.documentElement is set to element foo, and f.tagName is "foo" (lowercase).