Loading invalid XML
Hi,
I tried finding information about this but found nothing using google and the issue search here - but since this seems to be a relatively basic functionality I am almost sure the mistake is somewhere in my code - but I cannot find my error.
I use the following code in my QUnit test to load an invalid XML document (in my test case it contains a closing tag where there is no opening one):
test("PhantomJS - Invalid XML", function() {
expect(1);
var sXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><test></foo></test>";
var oParser = new DOMParser();
try {
var oDoc = oParser.parseFromString(oReq.responseText, "text/xml");
ok (oDoc.getElementsByTagName("parsererror").length > 0, "Failed to load XML");
} catch (ex) {
ok(true, "SyntaxError caught");
}
});
The documentation says that DomParser.parseFromString() should create an XML document that contains parsererror-elements in case of invalid XML (see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser#Error_handling), but I only get an Doxument without those elements and I cannot find a way to tell that the XML was invalid.
Is this a known issue? Am I doing something wrong? Is there a way to check whether the XML was invalid?
Confirmed using this self-contained test case:
<!doctype html>
<pre id="results"></pre>
<script>
var res = document.getElementById("results");
function log(msg) {
res.appendChild(document.createTextNode(msg + "\n"));
}
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><test></foo></test>";
var parser = new DOMParser();
try {
var doc = parser.parseFromString(xml, "text/xml");
log("Number of parse errors: " +
doc.getElementsByTagName("parsererror").length)
} catch (ex) {
log("Exception: " + ex);
}
</script>
The result is Number of parse errors: 1 with Firefox, Chromium 41 (Blink 537.36), and Epiphany 3.14 (AppleWebKit/601.1). But it is Number of parse errors: 0 with PhantomJS 2.0 (AppleWebKit/538.1).
I regret to say that this will probably only be fixed when we next update to a newer version of Webkit. We don't, in general, have the resources to do anything about Webkit bugs ourselves. (But at least it looks like it has already been fixed by Webkit upstream.)
Great, thank you.
One additional question: Will the new webkit version be part of PhatomJS 2.x or can this only be addressed in 3.0?
@sirion Right now I'm not aware of a plan for future PhantomJS release numbering or schedule. That might be best brought up on the mailing list.
Quick update: The issue still persists in 2.1.1
Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!