Commit f761ae40 authored by Marco Bonardo's avatar Marco Bonardo
Browse files

Bug 1661949 - Can't search from the Address Bar with ? if keyword.enabled = false. r=adw, a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D89143
parent 58f0c289
......@@ -193,7 +193,24 @@ class ProvidersManager {
}
// Providers can use queryContext.sources to decide whether they want to be
// invoked or not.
updateSourcesIfEmpty(queryContext);
// The sources may be defined in the context, then the whole search string
// can be used for searching. Otherwise sources are extracted from prefs and
// restriction tokens, then restriction tokens must be filtered out of the
// search string.
let restrictToken = updateSourcesIfEmpty(queryContext);
if (restrictToken) {
queryContext.shouldFilterRestrictionTokens = true;
// If the restriction token has an equivalent source, then set it as
// restrictSource.
let restrictType = Object.entries(UrlbarTokenizer.RESTRICT).find(
e => e[1] == restrictToken.value
)?.[0];
if (
["SEARCH", "HISTORY", "OPENPAGE", "BOOKMARK"].includes(restrictType)
) {
queryContext.restrictSource = queryContext.sources[0];
}
}
logger.debug(`Context sources ${queryContext.sources}`);
let query = new Query(queryContext, controller, muxer, providers);
......@@ -601,10 +618,12 @@ class Query {
/**
* Updates in place the sources for a given UrlbarQueryContext.
* @param {UrlbarQueryContext} context The query context to examine
* @returns {object} The restriction token that was used to set sources, or
* undefined if there's no restriction token.
*/
function updateSourcesIfEmpty(context) {
if (context.sources && context.sources.length) {
return;
return false;
}
let acceptedSources = [];
// There can be only one restrict token about sources.
......@@ -677,4 +696,5 @@ function updateSourcesIfEmpty(context) {
}
}
context.sources = acceptedSources;
return restrictToken;
}
......@@ -334,6 +334,21 @@ add_task(async function() {
}),
],
});
info("Forced search through a restriction token, keyword.enabled = false");
query = "?bacon";
context = createContext(query, { isPrivate: false });
await check_results({
context,
matches: [
makeSearchResult(context, {
engineName: ENGINE_NAME,
heuristic: true,
query: "bacon",
}),
],
});
Services.prefs.setBoolPref("keyword.enabled", true);
info("visit two word query, keyword.enabled = true");
query = "bacon lovers";
......
......@@ -536,6 +536,14 @@ function Search(
}
}
// Eventually filter restriction tokens. In general it's a good idea, but if
// the consumer requested search mode, we should use the full string to avoid
// ignoring valid tokens.
this._searchTokens =
!queryContext || queryContext.shouldFilterRestrictionTokens
? this.filterTokens(tokens)
: tokens;
// The behavior can be set through:
// 1. a specific restrictSource in the QueryContext
// 2. typed restriction tokens
......@@ -544,7 +552,6 @@ function Search(
queryContext.restrictSource &&
sourceToBehaviorMap.has(queryContext.restrictSource)
) {
this._searchTokens = tokens;
this._behavior = 0;
this.setBehavior("restrict");
let behavior = sourceToBehaviorMap.get(queryContext.restrictSource);
......@@ -554,7 +561,6 @@ function Search(
// there is no _heuristicToken.
this._heuristicToken = null;
} else {
this._searchTokens = this.filterTokens(tokens);
// The heuristic token is the first filtered search token, but only when it's
// actually the first thing in the search string. If a prefix or restriction
// character occurs first, then the heurstic token is null. We use the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment