зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1094179 - use uriFixup for trimURL, r=dao
--HG-- extra : rebase_source : 2b779b615854513d0bfdce6f13fc56f00e69d29d
This commit is contained in:
Родитель
f9702f8d40
Коммит
c3882b9ccd
|
@ -41,7 +41,9 @@ function test() {
|
|||
testVal("ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org");
|
||||
|
||||
testVal("https://user:pass@mozilla.org/", "https://user:pass@mozilla.org");
|
||||
testVal("https://user@mozilla.org/", "https://user@mozilla.org");
|
||||
testVal("http://user:pass@mozilla.org/", "http://user:pass@mozilla.org");
|
||||
testVal("http://user@mozilla.org/", "user@mozilla.org");
|
||||
testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666");
|
||||
|
||||
testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext");
|
||||
|
@ -55,7 +57,16 @@ function test() {
|
|||
testVal("jar:http://mozilla.org/example.jar!/");
|
||||
testVal("view-source:http://mozilla.org/");
|
||||
|
||||
// Behaviour for hosts with no dots depends on the whitelist:
|
||||
let fixupWhitelistPref = "browser.fixup.domainwhitelist.localhost";
|
||||
Services.prefs.setBoolPref(fixupWhitelistPref, false);
|
||||
testVal("http://localhost");
|
||||
Services.prefs.setBoolPref(fixupWhitelistPref, true);
|
||||
testVal("http://localhost", "localhost");
|
||||
Services.prefs.clearUserPref(fixupWhitelistPref);
|
||||
|
||||
testVal("http:// invalid url");
|
||||
|
||||
testVal("http://someotherhostwithnodots");
|
||||
testVal("http://localhost/ foo bar baz");
|
||||
testVal("http://localhost.localdomain/ foo bar baz", "localhost.localdomain/ foo bar baz");
|
||||
|
|
|
@ -714,15 +714,25 @@ function trimURL(aURL) {
|
|||
// nsIURIFixup::createFixupURI with the result will produce a different URI.
|
||||
|
||||
// remove single trailing slash for http/https/ftp URLs
|
||||
let rv = aURL.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1");
|
||||
let url = aURL.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1");
|
||||
|
||||
// Strip the leading http:// only if the host has at least one '.' or
|
||||
// looks like an ipv6 ip:
|
||||
let hostMatch = rv.match(/^http:\/\/([^\/]*)/);
|
||||
let ipv6Regex = /\[[\da-f:]*\]/;
|
||||
if (hostMatch && (hostMatch[1].contains(".") || ipv6Regex.test(hostMatch[1]))) {
|
||||
/* remove http:// unless the host starts with "ftp\d*\." or contains "@" */
|
||||
rv = rv.replace(/^http:\/\/((?!ftp\d*\.)[^\/@]+(?:\/|$))/, "$1");
|
||||
// remove http://
|
||||
if (!url.startsWith("http://")) {
|
||||
return url;
|
||||
}
|
||||
return rv;
|
||||
let urlWithoutProtocol = url.substring(7);
|
||||
|
||||
let flags = Services.uriFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |
|
||||
Services.uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS;
|
||||
let fixedUpURL = Services.uriFixup.createFixupURI(urlWithoutProtocol, flags);
|
||||
let expectedURLSpec;
|
||||
try {
|
||||
expectedURLSpec = makeURI(aURL).spec;
|
||||
} catch (ex) {
|
||||
return url;
|
||||
}
|
||||
if (fixedUpURL.spec == expectedURLSpec) {
|
||||
return urlWithoutProtocol;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче