Bug 1083634 - Entering a trailing slash after a domain should not do a search. r=smaug, r=Unfocused, a=sledru
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 22 Dec 2014 00:03:26 +0000
changeset 242704 a000dbbffc107f3195357057ff42c55f29c4414f
parent 242703 0b319c8d846b9d6e276220a423998fdf19c51f25
child 242705 451ed5c44843dfedf4bc90d1aa5e7d44f4952a93
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, Unfocused, sledru
bugs1083634
milestone36.0a2
Bug 1083634 - Entering a trailing slash after a domain should not do a search. r=smaug, r=Unfocused, a=sledru
docshell/base/nsDefaultURIFixup.cpp
docshell/test/unit/test_nsDefaultURIFixup_info.js
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -1091,16 +1091,23 @@ nsDefaultURIFixup::KeywordURIFixup(const
     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)) {
             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) {
+            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);
     }
     return rv;
 }
 
 bool nsDefaultURIFixup::IsDomainWhitelisted(const nsAutoCString aAsciiHost,
--- a/docshell/test/unit/test_nsDefaultURIFixup_info.js
+++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js
@@ -371,16 +371,24 @@ let testcases = [ {
     input: "5+2",
     fixedURI: "http://5+2/",
     alternateURI: "http://www.5+2.com/",
     keywordLookup: true,
     protocolChange: true,
     affectedByWhitelist: true,
     affectedByDNSForSingleHosts: true,
   }, {
+    input: "5/2",
+    fixedURI: "http://5/2",
+    alternateURI: "http://www.5.com/2",
+    keywordLookup: true,
+    protocolChange: true,
+    affectedByWhitelist: true,
+    affectedByDNSForSingleHosts: true,
+  }, {
     input: "moz ?.::%27",
     keywordLookup: true,
     protocolChange: true
   }, {
     input: "mozilla.com/?q=search",
     fixedURI: "http://mozilla.com/?q=search",
     alternateURI: "http://www.mozilla.com/?q=search",
     protocolChange: true
@@ -443,16 +451,42 @@ let testcases = [ {
     affectedByWhitelist: true
   }, {
     input: "??mozilla",
     fixedURI: "http:///??mozilla",
     alternateURI: "http://www..com/??mozilla",
     keywordLookup: true,
     protocolChange: true,
     affectedByWhitelist: true
+  }, {
+    input: "mozilla/",
+    fixedURI: "http://mozilla/",
+    alternateURI: "http://www.mozilla.com/",
+    protocolChange: true,
+    affectedByWhitelist: true,
+  }, {
+    input: "mozilla",
+    fixedURI: "http://mozilla/",
+    alternateURI: "http://www.mozilla.com/",
+    protocolChange: true,
+    keywordLookup: true,
+    affectedByWhitelist: true,
+    affectedByDNSForSingleHosts: true,
+  }, {
+    input: "mozilla5/2",
+    fixedURI: "http://mozilla5/2",
+    alternateURI: "http://www.mozilla5.com/2",
+    protocolChange: true,
+    affectedByWhitelist: true,
+  }, {
+    input: "mozilla/foo",
+    fixedURI: "http://mozilla/foo",
+    alternateURI: "http://www.mozilla.com/foo",
+    protocolChange: true,
+    affectedByWhitelist: true,
   }];
 
 if (Services.appinfo.OS.toLowerCase().startsWith("win")) {
   testcases.push({
     input: "C:\\some\\file.txt",
     fixedURI: "file:///C:/some/file.txt",
     protocolChange: true,
   });
@@ -462,20 +496,18 @@ if (Services.appinfo.OS.toLowerCase().st
     alternateURI: "http://www.mozilla.com/",
     protocolChange: true,
     affectedByWhitelist: true,
   });
   testcases.push({
     input: "mozilla\\",
     fixedURI: "http://mozilla/",
     alternateURI: "http://www.mozilla.com/",
-    keywordLookup: true,
     protocolChange: true,
     affectedByWhitelist: true,
-    affectedByDNSForSingleHosts: true,
   });
 } else {
   testcases.push({
     input: "/some/file.txt",
     fixedURI: "file:///some/file.txt",
     protocolChange: true,
   });
   testcases.push({