mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1170334 - Re-escape entities in nsWebBrowserPersist XML stylesheet handling. r=hsivonen
--HG-- extra : rebase_source : c895f6b5c0cee1f2a35207f25ed8b653ac1cb591
This commit is contained in:
parent
fb709aaebc
commit
5813d28889
@ -2529,6 +2529,36 @@ nsWebBrowserPersist::EnumCleanupUploadList(nsISupports *aKey, UploadData *aData,
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
static void
|
||||
AppendXMLAttr(const nsAString& key, const nsAString& aValue, nsAString& aBuffer)
|
||||
{
|
||||
if (!aBuffer.IsEmpty()) {
|
||||
aBuffer.Append(' ');
|
||||
}
|
||||
aBuffer.Append(key);
|
||||
aBuffer.AppendLiteral("=\"");
|
||||
for (size_t i = 0; i < aValue.Length(); ++i) {
|
||||
switch (aValue[i]) {
|
||||
case '&':
|
||||
aBuffer.AppendLiteral("&");
|
||||
break;
|
||||
case '<':
|
||||
aBuffer.AppendLiteral("<");
|
||||
break;
|
||||
case '>':
|
||||
aBuffer.AppendLiteral(">");
|
||||
break;
|
||||
case '"':
|
||||
aBuffer.AppendLiteral(""");
|
||||
break;
|
||||
default:
|
||||
aBuffer.Append(aValue[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
aBuffer.Append('"');
|
||||
}
|
||||
|
||||
nsresult nsWebBrowserPersist::FixupXMLStyleSheetLink(nsIDOMProcessingInstruction *aPI, const nsAString &aHref)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPI);
|
||||
@ -2568,30 +2598,28 @@ nsresult nsWebBrowserPersist::FixupXMLStyleSheetLink(nsIDOMProcessingInstruction
|
||||
nsGkAtoms::media,
|
||||
media);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kCloseAttr, "\" ");
|
||||
nsAutoString newData;
|
||||
newData += NS_LITERAL_STRING("href=\"") + aHref + kCloseAttr;
|
||||
AppendXMLAttr(NS_LITERAL_STRING("href"), aHref, newData);
|
||||
if (!title.IsEmpty())
|
||||
{
|
||||
newData += NS_LITERAL_STRING("title=\"") + title + kCloseAttr;
|
||||
AppendXMLAttr(NS_LITERAL_STRING("title"), title, newData);
|
||||
}
|
||||
if (!media.IsEmpty())
|
||||
{
|
||||
newData += NS_LITERAL_STRING("media=\"") + media + kCloseAttr;
|
||||
AppendXMLAttr(NS_LITERAL_STRING("media"), media, newData);
|
||||
}
|
||||
if (!type.IsEmpty())
|
||||
{
|
||||
newData += NS_LITERAL_STRING("type=\"") + type + kCloseAttr;
|
||||
AppendXMLAttr(NS_LITERAL_STRING("type"), type, newData);
|
||||
}
|
||||
if (!charset.IsEmpty())
|
||||
{
|
||||
newData += NS_LITERAL_STRING("charset=\"") + charset + kCloseAttr;
|
||||
AppendXMLAttr(NS_LITERAL_STRING("charset"), charset, newData);
|
||||
}
|
||||
if (!alternate.IsEmpty())
|
||||
{
|
||||
newData += NS_LITERAL_STRING("alternate=\"") + alternate + kCloseAttr;
|
||||
AppendXMLAttr(NS_LITERAL_STRING("alternate"), alternate, newData);
|
||||
}
|
||||
newData.Truncate(newData.Length() - 1); // Remove the extra space on the end.
|
||||
aPI->SetData(newData);
|
||||
}
|
||||
|
||||
|
3
embedding/test/bug1170334_iframe.xml
Normal file
3
embedding/test/bug1170334_iframe.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml-stylesheet href="bug1170334_style.css" type="text/css" title=""?>FAIL"?>
|
||||
<thing/>
|
1
embedding/test/bug1170334_style.css
Normal file
1
embedding/test/bug1170334_style.css
Normal file
@ -0,0 +1 @@
|
||||
/* This stylesheet intentionally left blank. */
|
@ -3,6 +3,9 @@ skip-if = buildapp == 'b2g'
|
||||
support-files =
|
||||
320x240.ogv
|
||||
bug449141_page.html
|
||||
bug1170334_iframe.xml
|
||||
bug1170334_style.css
|
||||
|
||||
[test_bug449141.html]
|
||||
skip-if = toolkit == 'android'
|
||||
[test_bug1170334_wbp_xmlstyle.html]
|
||||
|
80
embedding/test/test_bug1170334_wbp_xmlstyle.html
Normal file
80
embedding/test/test_bug1170334_wbp_xmlstyle.html
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1170334
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 1170334 (nsWebBrowserPersist vs. XML stylesheets)</title>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1170334">Mozilla Bug 1170334</a>
|
||||
<p id="display"></p>
|
||||
<pre id="results"></pre>
|
||||
<div id="content">
|
||||
<iframe src="bug1170334_iframe.xml" id="iframe"></iframe>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript;version=1.7">
|
||||
const nameStem="test_bug1170334_" + Date.now();
|
||||
const { Ci, Cc, Cu, Cr } = SpecialPowers;
|
||||
let iframe = document.getElementById("iframe");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
iframe.onload = function iframe_onload1() {
|
||||
let doc = iframe.contentDocument;
|
||||
ok(doc, "iframe content document exists");
|
||||
|
||||
let wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
|
||||
.createInstance(Ci.nsIWebBrowserPersist);
|
||||
let ios = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
let tmp = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIProperties)
|
||||
.get("TmpD", Ci.nsIFile);
|
||||
let tmpFile = tmp.clone();
|
||||
tmpFile.append(nameStem + "_iframe.xml");
|
||||
let tmpDir = tmp.clone();
|
||||
tmpDir.append(nameStem + "_files");
|
||||
|
||||
// When the document in the iframe is saved, try to load the result.
|
||||
wbp.progressListener = {
|
||||
onProgressChange: function(){},
|
||||
onLocationChange: function(){},
|
||||
onStatusChange: function(){},
|
||||
onSecurityChange: function(){},
|
||||
onStateChange: function wbp_stateChange(_wbp, _req, state, status) {
|
||||
if ((state & Ci.nsIWebProgressListener.STATE_STOP) == 0) {
|
||||
return;
|
||||
}
|
||||
is(status, Cr.NS_OK, "nsWebBrowserPersist status");
|
||||
iframe.onload = function iframe_onload2() {
|
||||
let elem = iframe.contentDocument.documentElement;
|
||||
is(elem && elem.tagName, "thing", "document element tag");
|
||||
if (elem && elem.tagName == "parsererror") {
|
||||
ok(false, "Parser error: " + elem.textContent);
|
||||
}
|
||||
|
||||
cleanUp();
|
||||
SimpleTest.finish();
|
||||
};
|
||||
iframe.src = ios.newFileURI(tmpFile).spec;
|
||||
}
|
||||
};
|
||||
wbp.saveDocument(doc, tmpFile, tmpDir, null, 0, 0);
|
||||
|
||||
function cleanUp() {
|
||||
if (tmpFile.exists()) {
|
||||
tmpFile.remove(/* recursive: */ false);
|
||||
}
|
||||
if (tmpDir.exists()) {
|
||||
tmpDir.remove(/* recursive: */ true);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user