Bug 1636583 - URIFixup should force a visit when an uri-like search string ends with a slash. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 23 May 2020 13:24:44 +0000
changeset 531773 7e46c4fe1829474f4697b4c0d6a711436db8098d
parent 531772 79ef4e6927106b67cc0190c85563bf368dca6897
child 531774 3883a1bffcbee3c00df6c0388c16b86d707e36ec
push id37443
push usercbrindusan@mozilla.com
push dateSat, 23 May 2020 21:42:57 +0000
treeherdermozilla-central@9a2f741cef6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1636583
milestone78.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 1636583 - URIFixup should force a visit when an uri-like search string ends with a slash. r=adw Differential Revision: https://phabricator.services.mozilla.com/D75910
docshell/base/URIFixup.jsm
docshell/test/unit/test_URIFixup_info.js
--- a/docshell/base/URIFixup.jsm
+++ b/docshell/base/URIFixup.jsm
@@ -9,17 +9,17 @@
  * missing schemes.
  * URI references:
  *   http://www.faqs.org/rfcs/rfc1738.html
  *   http://www.faqs.org/rfcs/rfc2396.html
  */
 
 // getFixupURIInfo has a complex logic, that likely could be simplified, but
 // the risk of regressions is high, thus that should be done with care.
-/* eslint complexity: ["error", 39] */
+/* eslint complexity: ["error", 40] */
 
 var EXPORTED_SYMBOLS = ["URIFixup", "URIFixupInfo"];
 
 const { XPCOMUtils } = ChromeUtils.import(
   "resource://gre/modules/XPCOMUtils.jsm"
 );
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const { AppConstants } = ChromeUtils.import(
@@ -384,16 +384,21 @@ URIFixup.prototype = {
     // supposed to be tab-separated content.
     if (!isCommonProtocol && maxOneTabRegex.test(uriString)) {
       let uriWithProtocol = fixupURIProtocol(uriString);
       if (uriWithProtocol) {
         info.fixedURI = uriWithProtocol;
         info.fixupChangedProtocol = true;
         maybeSetAlternateFixedURI(info, fixupFlags);
         info.preferredURI = info.fixedURI;
+        // Check if it's a forced visit. The user can enforce a visit by
+        // appending a slash, but the string must be in a valid uri format.
+        if (uriString.endsWith("/")) {
+          return info;
+        }
       }
     }
 
     // See if it is a keyword and whether a keyword must be fixed up.
     if (
       keywordEnabled &&
       fixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP &&
       !inputHadDuffProtocol &&
--- a/docshell/test/unit/test_URIFixup_info.js
+++ b/docshell/test/unit/test_URIFixup_info.js
@@ -406,17 +406,17 @@ var testcases = [
   },
   {
     input: "café.com",
     fixedURI: "http://xn--caf-dma.com/",
     alternateURI: "http://www.xn--caf-dma.com/",
     protocolChange: true,
   },
   {
-    input: "mozilla.nonexistent/",
+    input: "mozilla.nonexistent",
     fixedURI: "http://mozilla.nonexistent/",
     alternateURI: "http://www.mozilla.nonexistent/",
     keywordLookup: true,
     protocolChange: true,
     affectedByDNSForSingleWordHosts: true,
   },
   {
     input: "mochi.ocm",
@@ -598,16 +598,32 @@ var testcases = [
     fixedURI: "http://mozilla.org/",
     alternateURI: "http://www.mozilla.org/",
     protocolChange: true,
   },
   {
     input: " moz\ti\tlla.org ",
     keywordLookup: true,
   },
+  {
+    input: "mozilla/",
+    fixedURI: "http://mozilla/",
+    alternateURI: "http://www.mozilla.com/",
+    protocolChange: true,
+  },
+  {
+    input: "mozilla/ test /",
+    fixedURI: "http://mozilla/%20test%20/",
+    alternateURI: "http://www.mozilla.com/%20test%20/",
+    protocolChange: true,
+  },
+  {
+    input: "mozilla /test/",
+    keywordLookup: true,
+  },
 ];
 
 if (AppConstants.platform == "win") {
   testcases.push({
     input: "C:\\some\\file.txt",
     fixedURI: "file:///C:/some/file.txt",
     protocolChange: true,
   });