Bug 1064430, part 1 - When punycode encoding <input type=email> content, only encode the domain labels. r=bz
authorJonathan Watt <jwatt@jwatt.org>
Wed, 28 Jan 2015 23:01:33 +0000
changeset 226555 05635e667f6171621fe42fa8a0040c73b116b293
parent 226554 7e34c1037f5edacb0e6977c3813bee1e99092869
child 226556 834eb207a19dc1775be14bd53aab8f374b2316b3
push id28200
push userkwierso@gmail.com
push dateThu, 29 Jan 2015 23:01:46 +0000
treeherdermozilla-central@4380ed39de3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1064430
milestone38.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 1064430, part 1 - When punycode encoding <input type=email> content, only encode the domain labels. r=bz
dom/html/HTMLInputElement.cpp
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -6616,25 +6616,24 @@ HTMLInputElement::HasStepMismatch(bool a
     return false;
   }
 
   // Value has to be an integral multiple of step.
   return NS_floorModulo(value - GetStepBase(), step) != Decimal(0);
 }
 
 /**
- * Splits the string on the first "@" character and punycode encodes the first
- * and second parts separately before rejoining them with an "@" and returning
- * the result via the aEncodedEmail out-param. Returns false if there is no
- * "@" caracter, if the "@" character is at the start or end, or if the
+ * Splits the string on the first "@" character and punycode encodes the second
+ * part (the domain labels) before rejoining the two parts with an "@" and
+ * returning the result via the aEncodedEmail out-param. Returns false if there
+ * is no "@" caracter, if the "@" character is at the start or end, or if the
  * conversion to punycode fails.
  *
  * This function exists because ConvertUTF8toACE() treats 'username@domain' as
- * a single label, but we need to encode the username and domain parts
- * separately.
+ * a single label, but we want to encode the domain parts only.
  */
 static bool PunycodeEncodeEmailAddress(const nsAString& aEmail,
                                        nsAutoCString& aEncodedEmail,
                                        uint32_t* aIndexOfAt)
 {
   nsAutoCString value = NS_ConvertUTF16toUTF8(aEmail);
   uint32_t length = value.Length();
 
@@ -6645,29 +6644,18 @@ static bool PunycodeEncodeEmailAddress(c
   }
 
   nsCOMPtr<nsIIDNService> idnSrv = do_GetService(NS_IDNSERVICE_CONTRACTID);
   if (!idnSrv) {
     NS_ERROR("nsIIDNService isn't present!");
     return false;
   }
 
-  const nsDependentCSubstring username = Substring(value, 0, atPos);
+  const nsDependentCSubstring domain = Substring(value, atPos + 1);
   bool ace;
-  if (NS_SUCCEEDED(idnSrv->IsACE(username, &ace)) && !ace) {
-    nsAutoCString usernameACE;
-    // TODO: Bug 901347: Usernames longer than 63 chars are not converted by
-    // ConvertUTF8toACE(). For now, continue on even if the conversion fails.
-    if (NS_SUCCEEDED(idnSrv->ConvertUTF8toACE(username, usernameACE))) {
-      value.Replace(0, atPos, usernameACE);
-      atPos = usernameACE.Length();
-    }
-  }
-
-  const nsDependentCSubstring domain = Substring(value, atPos + 1);
   if (NS_SUCCEEDED(idnSrv->IsACE(domain, &ace)) && !ace) {
     nsAutoCString domainACE;
     if (NS_FAILED(idnSrv->ConvertUTF8toACE(domain, domainACE))) {
       return false;
     }
     value.Replace(atPos + 1, domain.Length(), domainACE);
   }