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 53d9d0f commit 844ac38
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion parser/htmlparser/tests/mochitest/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ prefs =
[browser_viewsource.js]
support-files =
file_viewsource.html

[browser_elementindtd.js]
support-files =
browser_elementindtd.xml
browser_elementindtd.dtd
[browser_ysod_telemetry.js]
support-files =
broken_xml.xhtml
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>'>
25 changes: 25 additions & 0 deletions parser/htmlparser/tests/mochitest/browser_elementindtd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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 844ac38

Please sign in to comment.