diff --git a/browser/components/urlbar/UrlbarProviderAutofill.jsm b/browser/components/urlbar/UrlbarProviderAutofill.jsm index 78404452cd10..12f39d24a470 100644 --- a/browser/components/urlbar/UrlbarProviderAutofill.jsm +++ b/browser/components/urlbar/UrlbarProviderAutofill.jsm @@ -89,7 +89,7 @@ function originQuery(where) { OR (host BETWEEN 'www.' || :searchString AND 'www.' || :searchString || X'FFFF') ) SELECT :query_type AS query_type, - iif(instr(:searchString, "www."), host, fixed) || '/' AS host_fixed, + iif(instr(host, :searchString) = 1, host, fixed) || '/' AS host_fixed, ifnull(:prefix, host_prefix) || host || '/' AS url FROM origins ${where} diff --git a/browser/components/urlbar/tests/unit/test_autofill_bookmarked.js b/browser/components/urlbar/tests/unit/test_autofill_bookmarked.js index 27bed75d56b3..11d569f0be9b 100644 --- a/browser/components/urlbar/tests/unit/test_autofill_bookmarked.js +++ b/browser/components/urlbar/tests/unit/test_autofill_bookmarked.js @@ -83,7 +83,7 @@ add_task(async function() { { host } ); }); - await PlacesUtils.bookmarks.insert({ + bookmark = await PlacesUtils.bookmarks.insert({ url: `http://${host}`, parentGuid: PlacesUtils.bookmarks.unfiledGuid, }); @@ -91,6 +91,60 @@ add_task(async function() { await checkOriginsOrder(host, ["https://", "http://"]); await check_autofill(); + await PlacesUtils.history.clear(); + await PlacesUtils.bookmarks.remove(bookmark); +}); + +add_task(async function test_www() { + // Add a bookmark to the www version + let host = "example.com"; + await PlacesUtils.bookmarks.insert({ + url: `http://www.${host}`, + parentGuid: PlacesUtils.bookmarks.unfiledGuid, + }); + + info("search for start of www."); + let context = createContext("w", { isPrivate: false }); + await check_results({ + context, + autofilled: `www.${host}/`, + completed: `http://www.${host}/`, + matches: [ + makeVisitResult(context, { + uri: `http://www.${host}/`, + title: `www.${host}`, + heuristic: true, + }), + ], + }); + info("search for full www."); + context = createContext("www.", { isPrivate: false }); + await check_results({ + context, + autofilled: `www.${host}/`, + completed: `http://www.${host}/`, + matches: [ + makeVisitResult(context, { + uri: `http://www.${host}/`, + title: `www.${host}`, + heuristic: true, + }), + ], + }); + info("search for host without www."); + context = createContext("ex", { isPrivate: false }); + await check_results({ + context, + autofilled: `${host}/`, + completed: `http://www.${host}/`, + matches: [ + makeVisitResult(context, { + uri: `http://www.${host}/`, + title: `www.${host}`, + heuristic: true, + }), + ], + }); }); async function checkOriginsOrder(host, prefixOrder) {