Bug 997519 - Ensure that an valid encoding will be passed to nsTextToSubURI::UnEscapeAndConvert(). r=neil
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 18 Apr 2014 07:25:58 +0900
changeset 197714 b79f456a556696bcdabb01488ce1e33e71a52275
parent 197713 f3b7262a6f29cd0f8e078ecf4a012dd6da1fe693
child 197715 ae057f9c301bd110c96f57dae158e80295eac810
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs997519
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 997519 - Ensure that an valid encoding will be passed to nsTextToSubURI::UnEscapeAndConvert(). r=neil
netwerk/streamconv/converters/nsIndexedToHTML.cpp
--- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp
+++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp
@@ -242,20 +242,16 @@ nsIndexedToHTML::DoOnStartRequest(nsIReq
             uri->SetPath(path);
         }
         if (!path.EqualsLiteral("/")) {
             rv = uri->Resolve(NS_LITERAL_CSTRING(".."), parentStr);
             if (NS_FAILED(rv)) return rv;
         }
     }
 
-    nsXPIDLCString encoding;
-    rv = uri->GetOriginCharset(encoding);
-    if (NS_FAILED(rv)) return rv;
-
     buffer.AppendLiteral("<style type=\"text/css\">\n"
                          ":root {\n"
                          "  font-family: sans-serif;\n"
                          "}\n"
                          "img {\n"
                          "  border: 0;\n"
                          "}\n"
                          "th {\n"
@@ -484,16 +480,23 @@ nsIndexedToHTML::DoOnStartRequest(nsIReq
     // Everything needs to end in a /,
     // otherwise we end up linking to file:///foo/dirfile
 
     if (!mTextToSubURI) {
         mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
         if (NS_FAILED(rv)) return rv;
     }
 
+    nsXPIDLCString encoding;
+    rv = uri->GetOriginCharset(encoding);
+    if (NS_FAILED(rv)) return rv;
+    if (encoding.IsEmpty()) {
+      encoding.AssignLiteral("UTF-8");
+    }
+
     nsXPIDLString unEscapeSpec;
     rv = mTextToSubURI->UnEscapeAndConvert(encoding, titleUri.get(),
                                            getter_Copies(unEscapeSpec));
     // unescape may fail because
     // 1. file URL may be encoded in platform charset for backward compatibility
     // 2. query part may not be encoded in UTF-8 (see bug 261929)
     // so try the platform's default if this is file url
     if (NS_FAILED(rv) && isSchemeFile) {