mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1521366 - Searching for a space in the Quantum Bar causes an infinite loop. r=adw
Differential Revision: https://phabricator.services.mozilla.com/D19979 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
707fc46c31
commit
a5fe67550e
@ -173,7 +173,7 @@ var UrlbarTokenizer = {
|
||||
tokenize(queryContext) {
|
||||
logger.info("Tokenizing", queryContext);
|
||||
let searchString = queryContext.searchString;
|
||||
if (searchString.length == 0) {
|
||||
if (!searchString.trim()) {
|
||||
queryContext.tokens = [];
|
||||
return queryContext;
|
||||
}
|
||||
|
@ -221,7 +221,9 @@ var UrlbarUtils = {
|
||||
getTokenMatches(tokens, str) {
|
||||
return tokens.reduce((matches, token) => {
|
||||
let index = 0;
|
||||
while (index >= 0) {
|
||||
// Ideally we should never hit the empty token case, but just in case
|
||||
// the value check protects us from an infinite loop.
|
||||
while (index >= 0 && token.value) {
|
||||
index = str.indexOf(token.value, index);
|
||||
if (index >= 0) {
|
||||
let match = [index, token.value.length];
|
||||
|
@ -410,7 +410,7 @@ class UrlbarView {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (resultIndex == 0) {
|
||||
if (result.heuristic) {
|
||||
setAction(bundle.GetStringFromName("visit"));
|
||||
} else {
|
||||
setURL();
|
||||
|
@ -375,7 +375,7 @@ class UrlbarAbstraction {
|
||||
details.postData = postData;
|
||||
details.type = context.results[index].type;
|
||||
details.heuristic = context.results[index].heuristic;
|
||||
details.autofill = index == 0 && context.results[index].autofill;
|
||||
details.autofill = !!context.results[index].autofill;
|
||||
details.image = element.getElementsByClassName("urlbarView-favicon")[0].src;
|
||||
details.title = context.results[index].title;
|
||||
details.tags = "tags" in context.results[index].payload ?
|
||||
@ -407,12 +407,12 @@ class UrlbarAbstraction {
|
||||
details.autofill = style.includes("autofill");
|
||||
details.image = element.getAttribute("image");
|
||||
details.title = element.getAttribute("title");
|
||||
details.tags = [...element.getElementsByClassName("ac-tags")].map(e =>
|
||||
e.textContent);
|
||||
details.tags = style.includes("tag") ?
|
||||
[...element.getElementsByClassName("ac-tags")].map(e => e.textContent) : [];
|
||||
let typeIconStyle = this.window.getComputedStyle(element._typeIcon);
|
||||
details.displayed = {
|
||||
title: element._titleText.textContent,
|
||||
action: element._actionText.textContent,
|
||||
action: action ? element._actionText.textContent : "",
|
||||
typeIcon: typeIconStyle.listStyleImage,
|
||||
};
|
||||
if (details.type == UrlbarUtils.RESULT_TYPE.SEARCH) {
|
||||
|
@ -58,6 +58,7 @@ support-files =
|
||||
support-files =
|
||||
file_blank_but_not_blank.html
|
||||
[browser_urlbar_content_opener.js]
|
||||
[browser_urlbar_empty_search.js]
|
||||
[browser_urlbar_locationchange_urlbar_edit_dos.js]
|
||||
support-files =
|
||||
file_urlbar_edit_dos.html
|
||||
|
@ -0,0 +1,47 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
// This test ensures that a search for "empty" strings doesn't break the urlbar.
|
||||
|
||||
add_task(async function test_setup() {
|
||||
await PlacesTestUtils.addVisits([
|
||||
{
|
||||
uri: `http://one.mozilla.org/`,
|
||||
transition: PlacesUtils.history.TRANSITIONS.TYPED,
|
||||
},
|
||||
{
|
||||
uri: `http://two.mozilla.org/`,
|
||||
transition: PlacesUtils.history.TRANSITIONS.TYPED,
|
||||
},
|
||||
]);
|
||||
registerCleanupFunction(PlacesUtils.history.clear);
|
||||
});
|
||||
|
||||
add_task(async function test_empty() {
|
||||
info("Test searching for nothing");
|
||||
await promiseAutocompleteResultPopup("", window, true);
|
||||
// The first search collects the results, the following ones check results
|
||||
// are the same.
|
||||
let results = [{}]; // Add a fake first result, to account for heuristic.
|
||||
for (let i = 0; i < await UrlbarTestUtils.getResultCount(window); ++i) {
|
||||
results.push(await UrlbarTestUtils.getDetailsOfResultAt(window, i));
|
||||
}
|
||||
|
||||
for (let str of [" ", " "]) {
|
||||
info(`Test searching for "${str}"`);
|
||||
await promiseAutocompleteResultPopup(str, window, true);
|
||||
// Skip the heuristic result.
|
||||
Assert.ok((await UrlbarTestUtils.getDetailsOfResultAt(window, 0)).heuristic,
|
||||
"The first result is heuristic");
|
||||
let length = await UrlbarTestUtils.getResultCount(window);
|
||||
Assert.equal(length, results.length, "Comparing results count");
|
||||
for (let i = 1; i < length; ++i) {
|
||||
Assert.deepEqual(await UrlbarTestUtils.getDetailsOfResultAt(window, i),
|
||||
results[i],
|
||||
`Comparing result at index ${i}`);
|
||||
}
|
||||
}
|
||||
});
|
@ -100,6 +100,7 @@ support-files =
|
||||
support-files =
|
||||
../browser/file_blank_but_not_blank.html
|
||||
[../browser/browser_urlbar_content_opener.js]
|
||||
[../browser/browser_urlbar_empty_search.js]
|
||||
[../browser/browser_urlbar_locationchange_urlbar_edit_dos.js]
|
||||
support-files =
|
||||
../browser/file_urlbar_edit_dos.html
|
||||
|
@ -7,6 +7,10 @@ add_task(async function test_tokenizer() {
|
||||
searchString: "",
|
||||
expectedTokens: [],
|
||||
},
|
||||
{ desc: "Spaces string",
|
||||
searchString: " ",
|
||||
expectedTokens: [],
|
||||
},
|
||||
{ desc: "Single word string",
|
||||
searchString: "test",
|
||||
expectedTokens: [
|
||||
|
Loading…
Reference in New Issue
Block a user