Bug 1559008. Load catalog DTDs even if we don't have a useful DTD URI, since we ignore that URI anyway when we find a catalog DTD. r=peterv

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-06-24 12:45:22 +00:00
parent d8896fa841
commit 8c4e35413a
3 changed files with 49 additions and 8 deletions

View file

@ -189,11 +189,11 @@ static const nsCatalogData* LookupCatalogData(const char16_t* aPublicID) {
// This function provides a resource URI to a local DTD
// in resource://gre/res/dtd/ which may or may not exist.
// If aCatalogData is provided, it is used to remap the
// DTD instead of taking the filename from the URI.
// DTD instead of taking the filename from the URI. aDTD
// may be null in some cases that are relying on
// aCatalogData working for them.
static void GetLocalDTDURI(const nsCatalogData* aCatalogData, nsIURI* aDTD,
nsIURI** aResult) {
NS_ASSERTION(aDTD, "Null parameter.");
nsAutoCString fileName;
if (aCatalogData) {
// remap the DTD to a known local DTD
@ -207,6 +207,8 @@ static void GetLocalDTDURI(const nsCatalogData* aCatalogData, nsIURI* aDTD,
// special DTD directory and it will be picked.
nsCOMPtr<nsIURL> dtdURL = do_QueryInterface(aDTD);
if (!dtdURL) {
// Not a URL with a filename, or maybe it was null. Either way, nothing
// else we can do here.
return;
}
@ -599,13 +601,21 @@ nsresult nsExpatDriver::OpenInputStreamFromExternalDTD(const char16_t* aFPIStr,
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(aURLStr), nullptr,
baseURI);
NS_ENSURE_SUCCESS(rv, rv);
// Even if the URI is malformed (most likely because we have a
// non-hierarchical base URI and a relative DTD URI, with the latter
// being the normal XHTML DTD case), we can try to see whether we
// have catalog data for aFPIStr.
if (NS_WARN_IF(NS_FAILED(rv) && rv != NS_ERROR_MALFORMED_URI)) {
return rv;
}
// make sure the URI is allowed to be loaded in sync
// make sure the URI, if we have one, is allowed to be loaded in sync
bool isUIResource = false;
rv = NS_URIChainHasFlags(uri, nsIProtocolHandler::URI_IS_UI_RESOURCE,
&isUIResource);
NS_ENSURE_SUCCESS(rv, rv);
if (uri) {
rv = NS_URIChainHasFlags(uri, nsIProtocolHandler::URI_IS_UI_RESOURCE,
&isUIResource);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIURI> localURI;
if (!isUIResource) {

View file

@ -0,0 +1,4 @@
<!DOCTYPE html>
Test passes if it correctly shows &Aacute; in the subframe.
<hr>
<iframe srcdoc="&amp;Aacute"></iframe>

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>
Test that an XHTML document with a data: URL still handles the XHTML DTD
properly even if the DTD URL is given as a relative URL.
</title>
<link rel="author" title="Boris Zbarsky" href="bzbarsky@mit.edu">
<link rel="match" href="data-xhtml-with-dtd-ref.html">
</head>
<body>
Test passes if it correctly shows &Aacute; in the subframe.
<hr>
<!-- Document in the subframe is:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
&Aacute;
</body>
</html>
-->
<iframe src='data:application/xml,%3C%3Fxml%20version%3D%221.0%22%3F%3E%0A%3C!DOCTYPE%20html%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20XHTML%201.0%20Strict%2F%2FEN%22%20%22DTD%2Fxhtml1-strict.dtd%22%3E%0A%3Chtml%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%0A%20%20%3Cbody%3E%0A%20%20%20%20%26Aacute%3B%0A%20%20%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A'></iframe>