Bug 1545395 - Handle Search Engine urls properly where the search terms are in the url rather than as parameters. r=daleharvey
authorMark Banner <standard8@mozilla.com>
Tue, 30 Apr 2019 21:25:28 +0000
changeset 530867 38c57ccca71e24c90e73bfd2a06bd6a1de6b17db
parent 530866 47ea779dc66b06fdcc4a247fbe29bf9770cefa8b
child 530868 e607a590c53cf628517629383acbdc922534f8a9
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey
bugs1545395
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1545395 - Handle Search Engine urls properly where the search terms are in the url rather than as parameters. r=daleharvey Differential Revision: https://phabricator.services.mozilla.com/D29014
browser/components/extensions/test/xpcshell/test_ext_settings_overrides_search.js
toolkit/components/search/SearchService.jsm
--- a/browser/components/extensions/test/xpcshell/test_ext_settings_overrides_search.js
+++ b/browser/components/extensions/test/xpcshell/test_ext_settings_overrides_search.js
@@ -190,8 +190,44 @@ add_task(async function test_extension_p
 
   let expectedSuggestURL = kSearchSuggestURL.replace("{searchTerms}", kSearchTerm);
   let submissionSuggest = engine.getSubmission(kSearchTerm, URLTYPE_SUGGEST_JSON);
   equal(submissionSuggest.uri.spec, expectedSuggestURL, "Suggest URLs should match");
   equal(submissionSuggest.postData.data.data, "foo=bar&bar=foo", "Suggest postData should match");
 
   await ext1.unload();
 });
+
+add_task(async function test_extension_no_query_params() {
+  const ext1 = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "chrome_settings_overrides": {
+        "search_provider": {
+          "name": "MozSearch",
+          "keyword": "MozSearch",
+          "search_url": "https://example.com/{searchTerms}",
+          "suggest_url": "https://example.com/suggest/{searchTerms}",
+        },
+      },
+    },
+    useAddonManager: "temporary",
+  });
+
+  await ext1.startup();
+  await AddonTestUtils.waitForSearchProviderStartup(ext1);
+
+  let engine = Services.search.getEngineByName("MozSearch");
+  ok(engine, "Engine should exist.");
+
+  const encodedSubmissionURL = engine.getSubmission(kSearchTermIntl).uri.spec;
+  const testSubmissionURL = "https://example.com/" + encodeURIComponent(kSearchTermIntl);
+  equal(encodedSubmissionURL, testSubmissionURL, "Encoded UTF-8 URLs should match");
+
+  const expectedSuggestURL = "https://example.com/suggest/" + kSearchTerm;
+  let submissionSuggest = engine.getSubmission(kSearchTerm, URLTYPE_SUGGEST_JSON);
+  equal(submissionSuggest.uri.spec, expectedSuggestURL, "Suggest URLs should match");
+
+  await ext1.unload();
+  await delay();
+
+  engine = Services.search.getEngineByName("MozSearch");
+  ok(!engine, "Engine should not exist");
+});
--- a/toolkit/components/search/SearchService.jsm
+++ b/toolkit/components/search/SearchService.jsm
@@ -4052,24 +4052,27 @@ SearchService.prototype = {
       });
     }
 
     let params = {
       name: searchProvider.name.trim(),
       shortName: extension.id.split("@")[0],
       description: extension.manifest.description,
       searchForm: searchProvider.search_form,
-      template: searchProvider.search_url,
+      // AddonManager will sometimes encode the URL via `new URL()`. We want
+      // to ensure we're always dealing with decoded urls.
+      template: decodeURI(searchProvider.search_url),
       searchGetParams: searchProvider.search_url_get_params,
       searchPostParams: searchProvider.search_url_post_params,
       iconURL: searchProvider.favicon_url || preferredIconUrl,
       icons: iconList,
       alias: searchProvider.keyword,
       extensionID: extension.id,
       isBuiltin: extension.addonData.builtIn,
+      // suggest_url doesn't currently get encoded.
       suggestURL: searchProvider.suggest_url,
       suggestPostParams: searchProvider.suggest_url_post_params,
       suggestGetParams: searchProvider.suggest_url_get_params,
       queryCharset: searchProvider.encoding || "UTF-8",
       mozParams: searchProvider.params,
     };
 
     let localeMap = this._extensions.get(extension.id);