Bug 700566 - Pressing enter or copying URL on an http:// site whose hostname begins with "ftp<digit>" results in incorrect URL being loaded/copied. r=gavin
--- a/browser/base/content/test/browser_urlbarTrimURLs.js
+++ b/browser/base/content/test/browser_urlbarTrimURLs.js
@@ -27,17 +27,23 @@ function test() {
testVal("http://mozilla.imaginatory/", "mozilla.imaginatory");
testVal("http://www.mozilla.org/", "www.mozilla.org");
testVal("http://sub.mozilla.org/", "sub.mozilla.org");
testVal("http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org");
testVal("http://mozilla.org/file.ext", "mozilla.org/file.ext");
testVal("http://mozilla.org/sub/", "mozilla.org/sub/");
testVal("http://ftp.mozilla.org/", "http://ftp.mozilla.org");
+ testVal("http://ftp1.mozilla.org/", "http://ftp1.mozilla.org");
+ testVal("http://ftp42.mozilla.org/", "http://ftp42.mozilla.org");
+ testVal("http://ftpx.mozilla.org/", "ftpx.mozilla.org");
testVal("ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org");
+ testVal("ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org");
+ testVal("ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org");
+ testVal("ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org");
testVal("https://user:pass@mozilla.org/", "https://user:pass@mozilla.org");
testVal("http://user:pass@mozilla.org/", "http://user:pass@mozilla.org");
testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666");
testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext");
testVal("http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]");
testVal("https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -630,13 +630,15 @@ function openPrefsHelp() {
// since its probably behind the window.
var instantApply = getBoolPref("browser.preferences.instantApply");
var helpTopic = document.getElementsByTagName("prefwindow")[0].currentPane.helpTopic;
openHelpLink(helpTopic, !instantApply);
}
function trimURL(aURL) {
+ // This function must not modify the given URL such that calling
+ // nsIURIFixup::createFixupURI with the result will produce a different URI.
return aURL /* remove single trailing slash for http/https/ftp URLs */
.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1")
- /* remove http:// unless the host starts with "ftp." or contains "@" */
- .replace(/^http:\/\/((?!ftp\.)[^\/@]+(?:\/|$))/, "$1");
+ /* remove http:// unless the host starts with "ftp\d*\." or contains "@" */
+ .replace(/^http:\/\/((?!ftp\d*\.)[^\/@]+(?:\/|$))/, "$1");
}