bug 498433 Add [ ] to the EscapeURI whitelist, so that IPv6 literals get

serialized correctly.
r+sr=bz
This commit is contained in:
Christian Biesinger 2009-06-16 15:15:57 +02:00
Родитель 77b21ab250
Коммит f310605657
5 изменённых файлов: 116 добавлений и 2 удалений

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

@ -224,8 +224,9 @@ nsXHTMLContentSerializer::EscapeURI(nsIContent* aContent, const nsAString& aURI,
nsXPIDLCString escapedURI;
aEscapedURI.Truncate(0);
// Loop and escape parts by avoiding escaping reserved characters (and '%', '#' ).
while ((end = uri.FindCharInSet("%#;/?:@&=+$,", start)) != -1) {
// Loop and escape parts by avoiding escaping reserved characters
// (and '%', '#', as well as '[' and ']' for IPv6 address literals).
while ((end = uri.FindCharInSet("%#;/?:@&=+$,[]", start)) != -1) {
part = Substring(aURI, start, (end-start));
if (textToSubURI && !IsASCII(part)) {
rv = textToSubURI->ConvertAndEscape(mCharset.get(), part.get(), getter_Copies(escapedURI));

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

@ -310,6 +310,9 @@ _TEST_FILES = test_bug5141.html \
test_bug466751.xhtml \
test_bug461555.html \
test_sync_xhr_timer.xhtml \
file_htmlserializer_ipv6.html \
file_htmlserializer_ipv6_out.html \
test_bug498433.html \
$(NULL)
# Disabled; see bug 492181
# test_plugin_freezing.html

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

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testcase for IPv6 addresses</title>
<body>
<a href="http://[2001:4860:a003::68]/">Test</a>
</body>
</html>

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

@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testcase for IPv6 addresses</title>
</head><body>
<a href="http://[2001:4860:a003::68]/">Test</a>
</body></html>

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

@ -0,0 +1,94 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Test for HTML serializer</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=498433">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="testframe" src="file_htmlserializer_ipv6.html">
</iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
function loadFileContent(aFile, aCharset) {
if (aCharset == undefined)
aCharset = 'UTF-8';
var baseUri = Components.classes['@mozilla.org/network/standard-url;1']
.createInstance(Components.interfaces.nsIURI);
baseUri.spec = window.location.href;
var ios = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
var chann = ios.newChannel(aFile, aCharset, baseUri);
var cis = Components.interfaces.nsIConverterInputStream;
var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(cis);
inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
var str = {}, content = '';
while (inputStream.readString(4096, str) != 0) {
content += str.value;
}
return content;
}
function testHtmlSerializer_1 () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const de = Components.interfaces.nsIDocumentEncoder
var encoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=text/html"]
.createInstance(Components.interfaces.nsIDocumentEncoder);
var doc = $("testframe").contentDocument;
var out, expected;
// in the following tests, we must use the OutputLFLineBreak flag, to avoid
// to have the default line break of the platform in the result, so the test
// can pass on all platform
//------------ no flags
encoder.init(doc, "text/html", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_htmlserializer_ipv6_out.html");
is(out, expected, "test no flags");
//------------ OutputAbsoluteLinks
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_htmlserializer_ipv6_out.html");
is(out, expected, "test OutputAbsoluteLinks");
//------------ serializing a selection
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
encoder.setNode(doc.links[0]);
out = encoder.encodeToString();
expected = "<a href=\"http://[2001:4860:a003::68]/\">Test</a>";
is(out, expected, "test selection");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(testHtmlSerializer_1);
</script>
</pre>
</body>
</html>