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 179512 b79f456a556696bcdabb01488ce1e33e71a52275
parent 179511 f3b7262a6f29cd0f8e078ecf4a012dd6da1fe693
child 179513 ae057f9c301bd110c96f57dae158e80295eac810
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersneil
bugs997519
milestone31.0a1
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) {