Bug 1591761 - parseXULToFragment should throw a clearer exception for non-well-formed markup. r=bgrins

***
Bug 1591671, revert a breaking change in calling DOMParser.

Differential Revision: https://phabricator.services.mozilla.com/D50729

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexander J. Vincent 2019-10-29 23:04:14 +00:00
parent c092a45ba0
commit 0e30d06762
2 changed files with 14 additions and 0 deletions

View File

@ -521,6 +521,11 @@
`,
"application/xml"
);
if (doc.documentElement.localName === "parsererror") {
throw new Error("not well-formed XML");
}
// The XUL/XBL parser is set to ignore all-whitespace nodes, whereas (X)HTML
// does not do this. Most XUL code assumes that the whitespace has been
// stripped out, so we simply remove all text nodes after using the parser.

View File

@ -121,6 +121,15 @@
is(boxWithWhitespaceText.textContent, "", "Whitespace removed");
let boxWithNonWhitespaceText = MozXULElement.parseXULToFragment(`<box>foo</box>`).querySelector("box");
is(boxWithNonWhitespaceText.textContent, "foo", "Non-whitespace not removed");
try {
// we didn't encode the & as &amp;
MozXULElement.parseXULToFragment(`<box id="foo=1&bar=2"/>`);
ok(false, "parseXULToFragment should've thrown an exception for not-well-formed XML");
}
catch (ex) {
is(ex.message, "not well-formed XML", "parseXULToFragment threw the wrong message");
}
}
function testInheritAttributes() {