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

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexander J. Vincent 2019-10-28 21:59:59 +00:00
Родитель ec63a27082
Коммит 369ca66a21
2 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -498,8 +498,7 @@
* but excluding any text node.
*/
static parseXULToFragment(str, entities = []) {
let doc = gXULDOMParser.parseFromSafeString(
`
let fullSrc = `
${
entities.length
? `<!DOCTYPE bindings [
@ -518,9 +517,13 @@
xmlns:html="http://www.w3.org/1999/xhtml">
${str}
</box>
`,
"application/xml"
);
`;
let doc = gXULDOMParser.parseFromString(fullSrc, "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.

Просмотреть файл

@ -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() {