Bug 1632804 - Dedupe visits with empty URL hashes (trailing #). r=mak

Differential Revision: https://phabricator.services.mozilla.com/D72373
This commit is contained in:
Dão Gottwald 2020-04-27 19:33:09 +00:00
Родитель 44457e4de6
Коммит 0b5c0afcd0
3 изменённых файлов: 52 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,40 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_duplicates() {
const TEST_URL = "https://history.mozilla.org/";
await PlacesTestUtils.addVisits([
{ uri: TEST_URL, title: "Test history" },
{ uri: TEST_URL + "?#", title: "Test history" },
{ uri: TEST_URL + "#", title: "Test history" },
]);
let controller = UrlbarTestUtils.newMockController();
let searchString = "^Hist";
let context = createContext(searchString, { isPrivate: false });
await controller.startQuery(context);
info(
"Results:\n" +
context.results.map(m => `${m.title} - ${m.payload.url}`).join("\n")
);
Assert.equal(
context.results.length,
1,
"Found the expected number of matches"
);
Assert.equal(
context.results[0].type,
UrlbarUtils.RESULT_TYPE.URL,
"Should have a history result"
);
Assert.equal(
context.results[0].payload.url,
TEST_URL + "#",
"Check result URL"
);
await PlacesUtils.history.clear();
});

Просмотреть файл

@ -10,6 +10,7 @@ support-files =
[test_providersManager_filtering.js]
[test_providersManager_maxResults.js]
[test_providerUnifiedComplete.js]
[test_providerUnifiedComplete_duplicate_entries.js]
[test_queryScorer.js]
[test_search_suggestions.js]
[test_search_suggestions_aliases.js]

Просмотреть файл

@ -494,6 +494,8 @@ function stripAnyPrefix(str) {
* Whether to trim the trailing slash.
* @param {boolean} options.trimEmptyQuery
* Whether to trim a trailing `?`.
* @param {boolean} options.trimEmptyHash
* Whether to trim a trailing `#`.
* @returns {array} [modified, prefix, suffix]
* modified: {string} The modified spec.
* prefix: {string} The parts stripped from the prefix, if any.
@ -513,13 +515,17 @@ function stripPrefixAndTrim(spec, options = {}) {
spec = spec.slice(4);
prefix += "www.";
}
if (options.trimSlash && spec.endsWith("/")) {
if (options.trimEmptyHash && spec.endsWith("#")) {
spec = spec.slice(0, -1);
suffix += "/";
suffix = "#" + suffix;
}
if (options.trimEmptyQuery && spec.endsWith("?")) {
spec = spec.slice(0, -1);
suffix += "?";
suffix = "?" + suffix;
}
if (options.trimSlash && spec.endsWith("/")) {
spec = spec.slice(0, -1);
suffix = "/" + suffix;
}
return [spec, prefix, suffix];
}
@ -558,8 +564,9 @@ function makeKeyForMatch(match) {
stripHttp: true,
stripHttps: true,
stripWww: true,
trimEmptyQuery: true,
trimSlash: true,
trimEmptyQuery: true,
trimEmptyHash: true,
});
return [key, prefix, null];
}