Bug 1047600 - duff protocol should never keyword search. r=smaug, a=sledru
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 06 Aug 2014 12:36:27 +0100
changeset 217407 c5f014796d364a7fbaa5f1faf5be6d3e5ad49060
parent 217406 05c1785ef9592ceb1e8f8f51da158667c3ab6983
child 217408 013fd839967c666b6a19ada40625bb6afce40fda
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, sledru
bugs1047600
milestone33.0a2
Bug 1047600 - duff protocol should never keyword search. r=smaug, a=sledru
docshell/base/nsDefaultURIFixup.cpp
docshell/test/unit/test_nsDefaultURIFixup_info.js
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -339,27 +339,44 @@ nsDefaultURIFixup::GetFixupURIInfo(const
             info->mFixupCreatedAlternateURI = MakeAlternateURI(uri);
         info->mPreferredURI = uri;
         return NS_OK;
     }
 
     // Fix up protocol string before calling KeywordURIFixup, because
     // it cares about the hostname of such URIs:
     nsCOMPtr<nsIURI> uriWithProtocol;
+    bool inputHadDuffProtocol = false;
+
+    // Prune duff protocol schemes
+    //
+    //   ://totallybroken.url.com
+    //   //shorthand.url.com
+    //
+    if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("://")))
+    {
+        uriString = StringTail(uriString, uriString.Length() - 3);
+        inputHadDuffProtocol = true;
+    } else if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("//"))) {
+        uriString = StringTail(uriString, uriString.Length() - 2);
+        inputHadDuffProtocol = true;
+    }
+
     // NB: this rv gets returned at the end of this method if we never
     // do a keyword fixup after this (because the pref or the flags passed
     // might not let us).
     rv = FixupURIProtocol(uriString, info, getter_AddRefs(uriWithProtocol));
     if (uriWithProtocol) {
         info->mFixedURI = uriWithProtocol;
     }
 
     // See if it is a keyword
     // Test whether keywords need to be fixed up
-    if (sFixupKeywords && (aFixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP)) {
+    if (sFixupKeywords && (aFixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP) &&
+        !inputHadDuffProtocol) {
         KeywordURIFixup(uriString, info, aPostData);
         if (info->mPreferredURI)
             return NS_OK;
     }
 
     // Did the caller want us to try an alternative URI?
     // If so, attempt to fixup http://foo into http://www.foo.com
 
@@ -723,30 +740,16 @@ nsresult nsDefaultURIFixup::ConvertFileT
 nsresult
 nsDefaultURIFixup::FixupURIProtocol(const nsACString & aURIString,
                                     nsDefaultURIFixupInfo* aFixupInfo,
                                     nsIURI** aURI)
 {
     nsAutoCString uriString(aURIString);
     *aURI = nullptr;
 
-    // Prune duff protocol schemes
-    //
-    //   ://totallybroken.url.com
-    //   //shorthand.url.com
-    //
-    if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("://")))
-    {
-        uriString = StringTail(uriString, uriString.Length() - 3);
-    }
-    else if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("//")))
-    {
-        uriString = StringTail(uriString, uriString.Length() - 2);
-    }
-
     // Add ftp:// or http:// to front of url if it has no spec
     //
     // Should fix:
     //
     //   no-scheme.com
     //   ftp.no-scheme.com
     //   ftp4.no-scheme.com
     //   no-scheme.com/query?foo=http://www.foo.com
--- a/docshell/test/unit/test_nsDefaultURIFixup_info.js
+++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js
@@ -60,18 +60,20 @@ let testcases = [
   [".test", "http://.test/", "http://www..test/", true, true],
   ["mozilla is amazing", null, null, true, true],
   ["", null, null, true, true],
   ["[]", null, null, true, true]
 ];
 
 if (Services.appinfo.OS.toLowerCase().startsWith("win")) {
   testcases.push(["C:\\some\\file.txt", "file:///C:/some/file.txt", null, false, true]);
+  testcases.push(["//mozilla", "http://mozilla/", "http://www.mozilla.com/", false, true]);
 } else {
   testcases.push(["/some/file.txt", "file:///some/file.txt", null, false, true]);
+  testcases.push(["//mozilla", "file:////mozilla", null, false, true]);
 }
 
 function run_test() {
   for (let [testInput, expectedFixedURI, alternativeURI,
             expectKeywordLookup, expectProtocolChange] of testcases) {
     for (let flags of flagInputs) {
       let info;
       let fixupURIOnly = null;