Bug 1101625 part 2 - Remove the aIRI param since it's always true. And some minor code cleanup. r=smontagu
authorMats Palmgren <mats@mozilla.com>
Mon, 01 Dec 2014 15:55:15 +0000
changeset 218172 c2301fd8921b495932a801858863bab695b1241e
parent 218171 be23ef5730dce08c3d636fc670a5bf85c56b3f3b
child 218173 fdc27ab62b4f67fbe31dd6ca446e425a1de121f3
push id27919
push userphilringnalda@gmail.com
push dateTue, 02 Dec 2014 03:07:26 +0000
treeherdermozilla-central@265e01c7ff55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu
bugs1101625
milestone37.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 1101625 part 2 - Remove the aIRI param since it's always true. And some minor code cleanup. r=smontagu
intl/uconv/nsTextToSubURI.cpp
intl/uconv/nsTextToSubURI.h
--- a/intl/uconv/nsTextToSubURI.cpp
+++ b/intl/uconv/nsTextToSubURI.cpp
@@ -165,52 +165,47 @@ static bool statefulCharset(const char *
       !nsCRT::strcasecmp(charset, "HZ-GB-2312"))
     return true;
 
   return false;
 }
 
 nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
                                              const nsAFlatCString &aURI, 
-                                             bool aIRI, 
                                              nsAString &_retval)
 {
-  nsresult rv = NS_OK;
-
   // check for 7bit encoding the data may not be ASCII after we decode
   bool isStatefulCharset = statefulCharset(aCharset.get());
 
-  if (!isStatefulCharset && IsASCII(aURI)) {
-    CopyASCIItoUTF16(aURI, _retval);
-    return rv;
-  }
-
-  if (!isStatefulCharset && aIRI) {
+  if (!isStatefulCharset) {
+    if (IsASCII(aURI)) {
+      CopyASCIItoUTF16(aURI, _retval);
+      return NS_OK;
+    }
     if (IsUTF8(aURI)) {
       CopyUTF8toUTF16(aURI, _retval);
-      return rv;
+      return NS_OK;
     }
   }
 
   // empty charset could indicate UTF-8, but aURI turns out not to be UTF-8.
   NS_ENSURE_FALSE(aCharset.IsEmpty(), NS_ERROR_INVALID_ARG);
 
   nsAutoCString encoding;
   if (!EncodingUtils::FindEncodingForLabelNoReplacement(aCharset, encoding)) {
     return NS_ERROR_UCONV_NOCONV;
   }
   nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder =
     EncodingUtils::DecoderForEncoding(encoding);
 
-  NS_ENSURE_SUCCESS(rv, rv);
   unicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
 
   int32_t srcLen = aURI.Length();
   int32_t dstLen;
-  rv = unicodeDecoder->GetMaxLength(aURI.get(), srcLen, &dstLen);
+  nsresult rv = unicodeDecoder->GetMaxLength(aURI.get(), srcLen, &dstLen);
   NS_ENSURE_SUCCESS(rv, rv);
 
   char16_t *ustr = (char16_t *) NS_Alloc(dstLen * sizeof(char16_t));
   NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);
 
   rv = unicodeDecoder->Convert(aURI.get(), &srcLen, ustr, &dstLen);
 
   if (NS_SUCCEEDED(rv))
@@ -229,23 +224,23 @@ NS_IMETHODIMP  nsTextToSubURI::UnEscapeU
   // skip control octets (0x00 - 0x1f and 0x7f) when unescaping
   NS_UnescapeURL(PromiseFlatCString(aURIFragment), 
                  esc_SkipControl | esc_AlwaysCopy, unescapedSpec);
 
   // in case of failure, return escaped URI
   // Test for != NS_OK rather than NS_FAILED, because incomplete multi-byte
   // sequences are also considered failure in this context
   if (convertURItoUnicode(
-                PromiseFlatCString(aCharset), unescapedSpec, true, _retval)
+                PromiseFlatCString(aCharset), unescapedSpec, _retval)
       != NS_OK) {
     // assume UTF-8 instead of ASCII  because hostname (IDN) may be in UTF-8
     CopyUTF8toUTF16(aURIFragment, _retval);
   }
 
-  // if there are any characters that are unsafe for IRIs, reescape.
+  // If there are any characters that are unsafe for URIs, reescape those.
   if (mUnsafeChars.IsEmpty()) {
     nsCOMPtr<nsISupportsString> blacklist;
     nsresult rv = mozilla::Preferences::GetComplex("network.IDN.blacklist_chars",
                                                    NS_GET_IID(nsISupportsString),
                                                    getter_AddRefs(blacklist));
     if (NS_SUCCEEDED(rv)) {
       nsString chars;
       blacklist->ToString(getter_Copies(chars));
@@ -284,12 +279,12 @@ NS_IMETHODIMP  nsTextToSubURI::UnEscapeN
        aCharset.LowerCaseEqualsLiteral("utf-16be") ||
        aCharset.LowerCaseEqualsLiteral("utf-16le") ||
        aCharset.LowerCaseEqualsLiteral("utf-7") ||
        aCharset.LowerCaseEqualsLiteral("x-imap4-modified-utf7"))){
     CopyASCIItoUTF16(aURIFragment, _retval);
     return NS_OK;
   }
 
-  return convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec, true, _retval);
+  return convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec, _retval);
 }
 
 //----------------------------------------------------------------------
--- a/intl/uconv/nsTextToSubURI.h
+++ b/intl/uconv/nsTextToSubURI.h
@@ -1,40 +1,31 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vim: set ts=2 et sw=2 tw=80:
+// This Source Code is subject to the terms of the Mozilla Public License
+// version 2.0 (the "License"). You can obtain a copy of the License at
+// http://mozilla.org/MPL/2.0/.
 #ifndef nsTextToSubURI_h__
 #define nsTextToSubURI_h__
 
 #include "nsITextToSubURI.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
-//==============================================================
-class nsTextToSubURI: public nsITextToSubURI {
+class nsTextToSubURI: public nsITextToSubURI
+{
   NS_DECL_ISUPPORTS
   NS_DECL_NSITEXTTOSUBURI
 
 private:
   virtual ~nsTextToSubURI();
 
-  // IRI is "Internationalized Resource Identifiers"
-  // http://www.ietf.org/internet-drafts/draft-duerst-iri-01.txt
-  // 
-  // if the IRI option is true then we assume that the URI is encoded as UTF-8
-  // note: there is no definite way to distinguish between IRI and a URI encoded 
-  // with a non-UTF-8 charset
-  // Use this option carefully -- it may cause dataloss
-  // (recommended to set to true for UI purpose only)
-  //
+  // We assume that the URI is encoded as UTF-8.
   nsresult convertURItoUnicode(const nsAFlatCString &aCharset,
                                const nsAFlatCString &aURI, 
-                               bool aIRI, 
                                nsAString &_retval);
 
   // Characters from the pref "network.IDN.blacklist_chars", or a built-in
   // fallback if reading the pref fails.
   nsTArray<char16_t> mUnsafeChars;
 };
 
 #endif // nsTextToSubURI_h__
-