Bug 393246 - "CreateFixupURI should use UTF-8, not the system charset" [p=dao@mozilla.com (Dão Gottwald) r+sr=biesi a1.9=beltzner]
authorreed@reedloden.com
Tue, 18 Mar 2008 12:29:16 -0700
changeset 13244 c77477952b2fad42fa730075f27eb8268ef4492e
parent 13243 85d136c46a3f4ec11beec876c0b3dd8b62faaf89
child 13245 cc7343859836fcd3ae8af631d1406ec266bc0ccf
push idunknown
push userunknown
push dateunknown
bugs393246
milestone1.9b5pre
Bug 393246 - "CreateFixupURI should use UTF-8, not the system charset" [p=dao@mozilla.com (Dão Gottwald) r+sr=biesi a1.9=beltzner]
docshell/base/nsDefaultURIFixup.cpp
docshell/base/nsDefaultURIFixup.h
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -41,17 +41,16 @@
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsNetUtil.h"
 #include "nsEscape.h"
 #include "nsCRT.h"
 
 #include "nsIPrefService.h"
 #include "nsIPrefLocalizedString.h"
-#include "nsIPlatformCharset.h"
 #include "nsILocalFile.h"
 
 #include "nsIURIFixup.h"
 #include "nsDefaultURIFixup.h"
 
 /* Implementation file */
 NS_IMPL_ISUPPORTS1(nsDefaultURIFixup, nsIURIFixup)
 
@@ -227,38 +226,26 @@ nsDefaultURIFixup::CreateFixupURI(const 
                 if (*start == '\\')
                     *start = '/';
                 ++start;
             }
         }
 #endif
     }
 
-    // For these protocols, use system charset instead of the default UTF-8,
-    // if the URI is non ASCII.
-    PRBool bAsciiURI = IsASCII(uriString);
-    PRBool bUseNonDefaultCharsetForURI =
-                        !bAsciiURI &&
-                        (scheme.IsEmpty() ||
-                         scheme.LowerCaseEqualsLiteral("http") ||
-                         scheme.LowerCaseEqualsLiteral("https") ||
-                         scheme.LowerCaseEqualsLiteral("ftp") ||
-                         scheme.LowerCaseEqualsLiteral("file"));
-
     // Now we need to check whether "scheme" is something we don't
     // really know about.
     nsCOMPtr<nsIProtocolHandler> ourHandler, extHandler;
     
     ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(ourHandler));
     extHandler = do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default");
     
     if (ourHandler != extHandler || !PossiblyHostPortUrl(uriString)) {
         // Just try to create an URL out of it
-        rv = NS_NewURI(aURI, uriString,
-                       bUseNonDefaultCharsetForURI ? GetCharsetForUrlBar() : nsnull);
+        rv = NS_NewURI(aURI, uriString, nsnull);
 
         if (!*aURI && rv != NS_ERROR_MALFORMED_URI) {
             return rv;
         }
     }
     
     if (*aURI) {
         if (aFixupFlags & FIXUP_FLAGS_MAKE_ALTERNATE_URI)
@@ -318,23 +305,19 @@ nsDefaultURIFixup::CreateFixupURI(const 
         nsCAutoString hostSpec;
         uriString.Left(hostSpec, hostPos);
 
         // insert url spec corresponding to host name
         if (IsLikelyFTP(hostSpec))
             uriString.Assign(NS_LITERAL_CSTRING("ftp://") + uriString);
         else 
             uriString.Assign(NS_LITERAL_CSTRING("http://") + uriString);
-
-        // For ftp & http, we want to use system charset.
-        if (!bAsciiURI)
-          bUseNonDefaultCharsetForURI = PR_TRUE;
     } // end if checkprotocol
 
-    rv = NS_NewURI(aURI, uriString, bUseNonDefaultCharsetForURI ? GetCharsetForUrlBar() : nsnull);
+    rv = NS_NewURI(aURI, uriString, nsnull);
 
     // Did the caller want us to try an alternative URI?
     // If so, attempt to fixup http://foo into http://www.foo.com
 
     if (*aURI && aFixupFlags & FIXUP_FLAGS_MAKE_ALTERNATE_URI) {
         MakeAlternateURI(*aURI);
     }
 
@@ -751,51 +734,16 @@ PRBool nsDefaultURIFixup::PossiblyByteEx
     {
         if (*iter >= 0x0080 && *iter <= 0x00FF)
             return PR_TRUE;
         ++iter;
     }
     return PR_FALSE;
 }
 
-const char * nsDefaultURIFixup::GetFileSystemCharset()
-{
-  if (mFsCharset.IsEmpty())
-  {
-    nsresult rv;
-    nsCAutoString charset;
-    nsCOMPtr<nsIPlatformCharset> plat(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv));
-    if (NS_SUCCEEDED(rv))
-      rv = plat->GetCharset(kPlatformCharsetSel_FileName, charset);
-
-    if (charset.IsEmpty())
-      mFsCharset.AssignLiteral("ISO-8859-1");
-    else
-      mFsCharset.Assign(charset);
-  }
-
-  return mFsCharset.get();
-}
-
-const char * nsDefaultURIFixup::GetCharsetForUrlBar()
-{
-  const char *charset = GetFileSystemCharset();
-#ifdef XP_MAC
-  // check for "x-mac-" prefix
-  if ((strlen(charset) >= 6) && charset[0] == 'x' && charset[2] == 'm')
-  {
-    if (!strcmp("x-mac-roman", charset))
-      return "ISO-8859-1";
-    // we can do more x-mac-xxxx mapping here
-    // or somewhere in intl code like nsIPlatformCharset.
-  }
-#endif
-  return charset;
-}
-
 nsresult nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString, 
                                             nsIURI** aURI)
 {
     // These are keyword formatted strings
     // "what is mozilla"
     // "what is mozilla?"
     // "docshell site:mozilla.org" - has no dot/colon in the first space-separated substring
     // "?mozilla" - anything that begins with a question mark
--- a/docshell/base/nsDefaultURIFixup.h
+++ b/docshell/base/nsDefaultURIFixup.h
@@ -63,16 +63,13 @@ private:
     /* additional members */
     nsresult FileURIFixup(const nsACString &aStringURI, nsIURI** aURI);
     nsresult ConvertFileToStringURI(const nsACString& aIn, nsCString& aOut);
     nsresult KeywordURIFixup(const nsACString &aStringURI, nsIURI** aURI);
     PRBool PossiblyByteExpandedFileName(const nsAString& aIn);
     PRBool PossiblyHostPortUrl(const nsACString& aUrl);
     PRBool MakeAlternateURI(nsIURI *aURI);
     PRBool IsLikelyFTP(const nsCString& aHostSpec);
-    const char * GetFileSystemCharset();
-    const char * GetCharsetForUrlBar();
 
     nsCOMPtr<nsIPrefBranch> mPrefBranch;
-    nsCAutoString mFsCharset;
 };
 
 #endif