Bug 1420395 - deal with IDN domains without protocols correctly in nsIURIFixup, r=valentin a=gchang DEVEDITION_58_0b8_RELEASE FIREFOX_58_0b8_BUILD1 FIREFOX_58_0b8_RELEASE
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 28 Nov 2017 14:28:58 +0000
changeset 445069 27dc691eb4a0e52b7da1d69f6b6dcf8bfbaef759
parent 445068 22a20bb50c44580894278edc9a3df19e4eb1b804
child 445070 bf36fc4bcc47f180edd777ddd10c5ca1d886da67
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin, gchang
bugs1420395
milestone58.0
Bug 1420395 - deal with IDN domains without protocols correctly in nsIURIFixup, r=valentin a=gchang MozReview-Commit-ID: DZYnxExcqdp
docshell/base/nsDefaultURIFixup.cpp
docshell/test/unit/test_nsDefaultURIFixup_info.js
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -919,63 +919,63 @@ nsDefaultURIFixup::KeywordURIFixup(const
 
   // If there are only colons and only hexadecimal characters ([a-z][0-9])
   // enclosed in [], then don't do a keyword lookup
   if (looksLikeIpv6) {
     return NS_OK;
   }
 
   nsAutoCString asciiHost;
-  nsAutoCString host;
+  nsAutoCString displayHost;
 
-  bool isValidAsciiHost =
+  bool isValidHost =
     aFixupInfo->mFixedURI &&
     NS_SUCCEEDED(aFixupInfo->mFixedURI->GetAsciiHost(asciiHost)) &&
     !asciiHost.IsEmpty();
 
-  bool isValidHost =
+  bool isValidDisplayHost =
     aFixupInfo->mFixedURI &&
-    NS_SUCCEEDED(aFixupInfo->mFixedURI->GetHost(host)) &&
-    !host.IsEmpty();
+    NS_SUCCEEDED(aFixupInfo->mFixedURI->GetDisplayHost(displayHost)) &&
+    !displayHost.IsEmpty();
 
   nsresult rv = NS_OK;
   // We do keyword lookups if a space or quote preceded the dot, colon
   // or question mark (or if the latter is not found, or if the input starts
   // with a question mark)
   if (((firstSpaceLoc < firstDotLoc || firstQuoteLoc < firstDotLoc) &&
        (firstSpaceLoc < firstColonLoc || firstQuoteLoc < firstColonLoc) &&
        (firstSpaceLoc < firstQMarkLoc || firstQuoteLoc < firstQMarkLoc)) ||
       firstQMarkLoc == 0) {
     rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo,
                                    aPostData);
-    // ... or when the host is the same as asciiHost and there are no
+    // ... or when the asciiHost is the same as displayHost and there are no
     // characters from [a-z][A-Z]
-  } else if (isValidAsciiHost && isValidHost && !hasAsciiAlpha &&
-             host.EqualsIgnoreCase(asciiHost.get())) {
+  } else if (isValidHost && isValidDisplayHost && !hasAsciiAlpha &&
+             asciiHost.EqualsIgnoreCase(displayHost.get())) {
     if (!sDNSFirstForSingleWords) {
       rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo,
                                      aPostData);
     }
   }
   // ... or if there is no question mark or colon, and there is either no
   // dot, or exactly 1 and it is the first or last character of the input:
   else if ((firstDotLoc == uint32_t(kNotFound) ||
             (foundDots == 1 && (firstDotLoc == 0 ||
                                 firstDotLoc == aURIString.Length() - 1))) &&
            firstColonLoc == uint32_t(kNotFound) &&
            firstQMarkLoc == uint32_t(kNotFound)) {
-    if (isValidAsciiHost && IsDomainWhitelisted(asciiHost, firstDotLoc)) {
+    if (isValidHost && IsDomainWhitelisted(asciiHost, firstDotLoc)) {
       return NS_OK;
     }
 
     // ... unless there are no dots, and a slash, and alpha characters, and
     // this is a valid host:
     if (firstDotLoc == uint32_t(kNotFound) &&
         lastSlashLoc != uint32_t(kNotFound) &&
-        hasAsciiAlpha && isValidAsciiHost) {
+        hasAsciiAlpha && isValidHost) {
       return NS_OK;
     }
 
     // If we get here, we don't have a valid URI, or we did but the
     // host is not whitelisted, so we do a keyword search *anyway*:
     rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo,
                                    aPostData);
   }
--- a/docshell/test/unit/test_nsDefaultURIFixup_info.js
+++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js
@@ -477,17 +477,22 @@ var testcases = [ {
   }, {
     input: "localhost:8080",
     fixedURI: "http://localhost:8080/",
     protocolChange: true,
   }, {
     input: "plonk:8080",
     fixedURI: "http://plonk:8080/",
     protocolChange: true,
-  }
+  }, {
+    input: "\u10E0\u10D4\u10D2\u10D8\u10E1\u10E2\u10E0\u10D0\u10EA\u10D8\u10D0.\u10D2\u10D4",
+    fixedURI: "http://xn--lodaehvb5cdik4g.xn--node/",
+    alternateURI: "http://www.xn--lodaehvb5cdik4g.xn--node/",
+    protocolChange: true,
+  },
 ];
 
 if (Services.appinfo.OS.toLowerCase().startsWith("win")) {
   testcases.push({
     input: "C:\\some\\file.txt",
     fixedURI: "file:///C:/some/file.txt",
     protocolChange: true,
   });