mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 1048857 - stripPrefix shouldn't empty out www or protocol tokens if there's nothing else in them, r=paolo
This commit is contained in:
parent
2acc986fde
commit
84351cdebc
@ -457,14 +457,18 @@ function getUnfilteredSearchTokens(searchString)
|
||||
function stripPrefix(spec)
|
||||
{
|
||||
["http://", "https://", "ftp://"].some(scheme => {
|
||||
if (spec.startsWith(scheme)) {
|
||||
// Strip protocol if not directly followed by a space
|
||||
if (spec.startsWith(scheme) && spec != scheme &&
|
||||
spec[scheme.length] != " ") {
|
||||
spec = spec.slice(scheme.length);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (spec.startsWith("www.")) {
|
||||
// Strip www. if not directly followed by a space
|
||||
if (spec.startsWith("www.") && spec != "www." &&
|
||||
spec[4] != " ") {
|
||||
spec = spec.slice(4);
|
||||
}
|
||||
return spec;
|
||||
|
@ -0,0 +1,41 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
add_task(function* test_protocol_trimming() {
|
||||
for (let prot of ["http", "https", "ftp"]) {
|
||||
let visit = {
|
||||
// Include the protocol in the query string to ensure we get matches (see bug 1059395)
|
||||
uri: NetUtil.newURI(prot + "://www.mozilla.org/test/?q=" + prot + encodeURIComponent("://") + "www.foo"),
|
||||
title: "Test title",
|
||||
transition: TRANSITION_TYPED
|
||||
};
|
||||
yield promiseAddVisits(visit);
|
||||
let matches = [{uri: visit.uri, title: visit.title}];
|
||||
|
||||
let inputs = [
|
||||
prot + "://",
|
||||
prot + ":// ",
|
||||
prot + ":// mo",
|
||||
prot + "://mo te",
|
||||
prot + "://www.",
|
||||
prot + "://www. ",
|
||||
prot + "://www. mo",
|
||||
prot + "://www.mo te",
|
||||
"www.",
|
||||
"www. ",
|
||||
"www. mo",
|
||||
"www.mo te"
|
||||
];
|
||||
for (let input of inputs) {
|
||||
do_log_info("Searching for: " + input);
|
||||
yield check_autocomplete({
|
||||
search: input,
|
||||
matches: matches
|
||||
});
|
||||
}
|
||||
|
||||
yield cleanup();
|
||||
}
|
||||
});
|
||||
|
@ -11,6 +11,7 @@ tail =
|
||||
[test_autocomplete_on_value_removed_479089.js]
|
||||
[test_autoFill_default_behavior.js]
|
||||
[test_avoid_middle_complete.js]
|
||||
[test_avoid_stripping_to_empty_tokens.js]
|
||||
[test_casing.js]
|
||||
[test_do_not_trim.js]
|
||||
[test_download_embed_bookmarks.js]
|
||||
|
Loading…
Reference in New Issue
Block a user