Bug #1630

DOMParser returns document in case of syntax error

Added by Giulio Moro about 8 years ago.

Status:NewStart date:2016-02-23
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

in core.js

var parser = new DOMParser();
                var xmlDoc = parser.parseFromString(xmlhttp.responseText, "application/xml");
                if (xmlDoc == null)
                {
                    createProjectSave('null');
                }
                var response = xmlDoc.childNodes[0];
                if (response.getAttribute('state') == "OK")
                {
                    var file = response.getElementsByTagName('file')[0];
                    console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B');
                    popup.showPopup();
                    popup.popupContent.innerHTML = null;
                    popup.popupContent.textContent = "Thank you!";
                } else {
                    var message = response.getElementsByTagName('message')[0];
                    errorSessionDump(message.textContent);
                }

if (xmllhttp.responseText === ""), then parseFromString does not throw exceptions, rather it returns a well-formed xml document containing an error message.

I experienced that sometimes when something wrong happens with the server then xmlhttp.responseText=="" , at which point the next few lines do not work as expected.
In particular, if (xmlDoc == null) does not make sense because it is never going to be (as mentioned , in case of error xlmDoc will be an xml-formatted error message).

Also available in: Atom PDF