Bug 989576 - Restore removed code doing percent-encode for non-ASCII bytes. r=michal.novotny
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 29 Mar 2014 16:28:48 +0900
changeset 176034 b93c9a7e21a574532eab52045a71292ab845ac9b
parent 176033 fc8a8379714c8f6751d24893d7e4561cc8248bf0
child 176035 2db12b4898e20cb65ee4a64327c8b33069f831ae
push id41667
push userVYV03354@nifty.ne.jp
push dateSat, 29 Mar 2014 07:29:36 +0000
treeherdermozilla-inbound@b93c9a7e21a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs989576
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 989576 - Restore removed code doing percent-encode for non-ASCII bytes. r=michal.novotny
netwerk/streamconv/converters/nsIndexedToHTML.cpp
--- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp
+++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp
@@ -728,16 +728,20 @@ nsIndexedToHTML::OnIndexAvailable(nsIReq
             break;
         default:
             pushBuffer.AppendLiteral("file");
             break;
     }
 
     pushBuffer.AppendLiteral("\" href=\"");
 
+    nsXPIDLCString encoding;
+    rv = mParser->GetEncoding(getter_Copies(encoding));
+    if (NS_FAILED(rv)) return rv;
+
     // need to escape links
     nsAutoCString locEscaped;
 
     // Adding trailing slash helps to recognize whether the URL points to a file
     // or a directory (bug #214405).
     if ((type == nsIDirIndex::TYPE_DIRECTORY) && (loc.Last() != '/')) {
         loc.Append('/');
     }
@@ -759,16 +763,22 @@ nsIndexedToHTML::OnIndexAvailable(nsIReq
         // that directory will be incorrect
         escFlags = esc_Forced | esc_OnlyASCII | esc_AlwaysCopy | esc_FileBaseName | esc_Colon | esc_Directory;
     }
     NS_EscapeURL(loc.get(), loc.Length(), escFlags, locEscaped);
     // esc_Directory does not escape the semicolons, so if a filename
     // contains semicolons we need to manually escape them.
     // This replacement should be removed in bug #473280
     locEscaped.ReplaceSubstring(";", "%3b");
+    if (!encoding.EqualsLiteral("UTF-8")) {
+        // Escape all non-ASCII bytes to preserve the raw value.
+        nsAutoCString outstr;
+        NS_EscapeURL(locEscaped, esc_AlwaysCopy | esc_OnlyNonASCII, outstr);
+        locEscaped = outstr;
+    }
     nsAdoptingCString htmlEscapedURL(nsEscapeHTML(locEscaped.get()));
     pushBuffer.Append(htmlEscapedURL);
 
     pushBuffer.AppendLiteral("\">");
 
     if (type == nsIDirIndex::TYPE_FILE || type == nsIDirIndex::TYPE_UNKNOWN) {
         pushBuffer.AppendLiteral("<img src=\"moz-icon://");
         int32_t lastDot = locEscaped.RFindChar('.');