Skip to content

Commit

Permalink
Bug 1539759 - Improve DTD entity handling. Testcase. r=Gijs
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderbeken committed Feb 14, 2022
1 parent af133ec commit 4fc8956
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parser/htmlparser/tests/mochitest/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ support-files =
[browser_ysod_telemetry.js]
support-files =
broken_xml.xhtml

[browser_elementindtd.js]
support-files =
browser_elementindtd.xml
browser_elementindtd.dtd
2 changes: 2 additions & 0 deletions parser/htmlparser/tests/mochitest/browser_elementindtd.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!ENTITY entitywithelement
'<p id="fromdtd">From dtd</p>'>
31 changes: 31 additions & 0 deletions parser/htmlparser/tests/mochitest/browser_elementindtd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/*
* Test for bug 1539759
* Loads a chrome XML document that has an exteernal DTD file with an entity
* that contains an element, and verifies that that element was not inserted
* into the document (but its content was).
*/

add_task(async function test() {
await BrowserTestUtils.withNewTab(
getRootDirectory(gTestPath) + "browser_elementindtd.xml",
async function(newBrowser) {
// NB: We load the chrome:// page in the parent process.
testNoElementFromEntity(newBrowser);
}
);
});

function testNoElementFromEntity(newBrowser) {
let doc = newBrowser.contentDocument;
is(doc.body.textContent, "From dtd", "Should load DTD.");
is(
doc.body.firstElementChild,
null,
"Shouldn't have an element inserted from the DTD"
);
}
10 changes: 10 additions & 0 deletions parser/htmlparser/tests/mochitest/browser_elementindtd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html
[
<!ENTITY % externaldtd SYSTEM "chrome://mochitests/content/browser/parser/htmlparser/tests/mochitest/browser_elementindtd.dtd" >
%externaldtd;
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
&entitywithelement;
</body>
</html>

0 comments on commit 4fc8956

Please sign in to comment.