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:
Marco Bonardo 2019-02-15 20:55:30 +00:00
parent 707fc46c31
commit a5fe67550e
8 changed files with 62 additions and 7 deletions

View File

@ -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;
}

View File

@ -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];

View File

@ -410,7 +410,7 @@ class UrlbarView {
}
break;
default:
if (resultIndex == 0) {
if (result.heuristic) {
setAction(bundle.GetStringFromName("visit"));
} else {
setURL();

View File

@ -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) {

View File

@ -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

View File

@ -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}`);
}
}
});

View File

@ -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

View File

@ -7,6 +7,10 @@ add_task(async function test_tokenizer() {
searchString: "",
expectedTokens: [],
},
{ desc: "Spaces string",
searchString: " ",
expectedTokens: [],
},
{ desc: "Single word string",
searchString: "test",
expectedTokens: [