diff --git a/docshell/base/nsDefaultURIFixup.cpp b/docshell/base/nsDefaultURIFixup.cpp index 6b75bde30003..81b077121bc4 100644 --- a/docshell/base/nsDefaultURIFixup.cpp +++ b/docshell/base/nsDefaultURIFixup.cpp @@ -748,13 +748,13 @@ bool nsDefaultURIFixup::PossiblyHostPortUrl(const nsACString& aUrl) { ++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! diff --git a/docshell/test/unit/test_nsDefaultURIFixup_search.js b/docshell/test/unit/test_nsDefaultURIFixup_search.js index df8c26d9a1bc..150adfd56033 100644 --- a/docshell/test/unit/test_nsDefaultURIFixup_search.js +++ b/docshell/test/unit/test_nsDefaultURIFixup_search.js @@ -83,6 +83,18 @@ var data = [ 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(