Bug 1558408 - fix fixup of host port URLs with querystrings or refs without forward slashes, r=valentin
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 13 Nov 2019 18:07:40 +0000
changeset 501772 2f0634afb2f364a2a82afbb03d8d89d99bab1f61
parent 501771 f51eb6400003531a012b932a4b19ab5e7d32e85e
child 501773 291ef4ef1773d3a6cf138975185cdef75010e76b
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1558408
milestone72.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 1558408 - fix fixup of host port URLs with querystrings or refs without forward slashes, r=valentin Differential Revision: https://phabricator.services.mozilla.com/D52847
docshell/base/nsDefaultURIFixup.cpp
docshell/test/unit/test_nsDefaultURIFixup_search.js
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -743,23 +743,23 @@ bool nsDefaultURIFixup::PossiblyHostPort
   }
   if (iter == iterEnd) {
     // No point continuing since there is no colon
     return false;
   }
   ++iter;
 
   // Count the number of digits after the colon and before the
-  // next forward slash (or end of string)
+  // next forward slash, question mark, hash sign, or end of string.
 
   uint32_t digitCount = 0;
   while (iter != iterEnd && digitCount <= 5) {
     if (IsAsciiDigit(*iter)) {
       digitCount++;
-    } else if (*iter == '/') {
+    } else if (*iter == '/' || *iter == '?' || *iter == '#') {
       break;
     } else {
       // Whatever it is, it ain't a port!
       return false;
     }
     ++iter;
   }
   if (digitCount == 0 || digitCount > 5) {
--- a/docshell/test/unit/test_nsDefaultURIFixup_search.js
+++ b/docshell/test/unit/test_nsDefaultURIFixup_search.js
@@ -79,16 +79,28 @@ var data = [
       (isWin ? "http:" : "file://") +
       "//user:pass@example.com:8080/this/is/a/test.html",
   },
   {
     wrong: "://user:pass@example.com:8080/this/is/a/test.html",
     fixed: "http://user:pass@example.com:8080/this/is/a/test.html",
   },
   {
+    wrong: "localhost:8080/?param=1",
+    fixed: "http://localhost:8080/?param=1",
+  },
+  {
+    wrong: "localhost:8080?param=1",
+    fixed: "http://localhost:8080/?param=1",
+  },
+  {
+    wrong: "localhost:8080#somewhere",
+    fixed: "http://localhost:8080/#somewhere",
+  },
+  {
     wrong: "whatever://this/is/a@b/test.html",
     fixed: kSearchEngineURL.replace(
       "{searchTerms}",
       encodeURIComponent("whatever://this/is/a@b/test.html")
     ),
   },
 ];