Skip to content

Commit

Permalink
Fix issue where no parsererror is returned on invalid XML (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 authored and fatso83 committed Jun 2, 2018
1 parent 929b9fe commit 9b5330f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/fake-xhr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,11 @@ FakeXMLHttpRequest.parseXML = function parseXML(text) {
try {
if (typeof DOMParser !== "undefined") {
var parser = new DOMParser();
var parsererrorNS = parser.parseFromString("INVALID", "text/xml")
.getElementsByTagName("parsererror")[0].namespaceURI;
var parsererrors = parser
.parseFromString("INVALID", "text/xml")
.getElementsByTagName("parsererror");
var parsererrorNS = parsererrors.length
? parsererrors[0].namespaceURI : "";
var result = parser.parseFromString(text, "text/xml");
return result.getElementsByTagNameNS(parsererrorNS, "parsererror").length
? null : result;
Expand Down

1 comment on commit 9b5330f

@bafolts
Copy link

@bafolts bafolts commented on 9b5330f Jun 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks.

Please sign in to comment.