diff --git a/JSDOMParser.js b/JSDOMParser.js index 7a51e8a..cf15bc0 100644 --- a/JSDOMParser.js +++ b/JSDOMParser.js @@ -611,6 +611,13 @@ }; var Element = function (tag) { + // We use this to find the closing tag. + this._matchingTag = tag; + // We're explicitly a non-namespace aware parser, we just pretend it's all HTML. + var lastColonIndex = tag.lastIndexOf(":"); + if (lastColonIndex != -1) { + tag = tag.substring(lastColonIndex + 1); + } this.attributes = []; this.childNodes = []; this.children = []; @@ -1119,7 +1126,7 @@ // If this isn't a void Element, read its child nodes if (!closed) { this.readChildren(node); - var closingTag = ""; + var closingTag = ""; if (!this.match(closingTag)) { this.error("expected '" + closingTag + "' and got " + this.html.substr(this.currentChar, closingTag.length)); return null; diff --git a/test/test-jsdomparser.js b/test/test-jsdomparser.js index 38ee52f..ac1b11d 100644 --- a/test/test-jsdomparser.js +++ b/test/test-jsdomparser.js @@ -320,3 +320,19 @@ describe("baseURI parsing", function() { checkBase("//absolute/path", "http://absolute/path"); }); }); + +describe("namespace workarounds", function() { + it("should handle random namespace information in the serialized DOM", function() { + var html = ""; + var doc = new JSDOMParser().parse(html); + var div = doc.getElementsByTagName("div")[0]; + expect(div.tagName).eql("DIV"); + expect(div.localName).eql("div"); + expect(div.firstChild.tagName).eql("SVG"); + expect(div.firstChild.localName).eql("svg"); + expect(div.firstChild.firstChild.tagName).eql("CLIPPATH"); + expect(div.firstChild.firstChild.localName).eql("clippath"); + expect(doc.documentElement).eql(doc.firstChild); + expect(doc.body).eql(doc.documentElement.firstChild); + }); +});