Commit 24e2fdb3 authored by Moritz Beier's avatar Moritz Beier Committed by mbeier@mozilla.com
Browse files

Bug 1964507 - Only offer "Add Search Engine" for GET forms. r=search-reviewers,Standard8

parent c5ad346f
Loading
Loading
Loading
Loading
+4 −24
Original line number Diff line number Diff line
@@ -27,18 +27,6 @@ const TESTS = [
    submission: "kitten",
    expected: "https://example.org/search?q=kitten&utf8%E2%9C%93=%E2%9C%93",
  },
  {
    action: "/search",
    method: "POST",
    charset: "UTF-8",
    fields: [
      { name: "q", value: "Some initial value", main: true },
      { name: "utf8✓", value: "", hidden: true },
    ],
    submission: "kitten",
    expected: "https://example.org/search",
    expectedPost: "q=kitten&utf8%E2%9C%93=%E2%9C%93",
  },
  {
    action: "/search",
    method: "GET",
@@ -51,18 +39,6 @@ const TESTS = [
    submission: "caff\u00E8+",
    expected: "https://example.org/search?q=caff%E8%2B&cb=true",
  },
  {
    action: "/search",
    method: "POST",
    charset: "windows-1252",
    fields: [
      { name: "q", main: true },
      { name: "foo", value: "bar" },
    ],
    submission: "caff\u00E8+",
    expected: "https://example.org/search",
    expectedPost: "q=caff%E8%2B&foo=bar",
  },
];

const URL_UTF_8 =
@@ -249,6 +225,10 @@ add_task(async function testSearchFieldDetection() {
  Assert.equal(isSearchField, false, "Method=dialog means no search field");

  form.method = "POST";
  isSearchField = SpellCheckHelper.isTargetASearchEngineField(input, window);
  Assert.equal(isSearchField, false, "Method=post means no search field");

  form.method = "GET";

  delete input.removeAttribute("name");
  isSearchField = SpellCheckHelper.isTargetASearchEngineField(input, window);
+4 −2
Original line number Diff line number Diff line
@@ -500,8 +500,10 @@ export var SpellCheckHelper = {
    return (
      // Forms without an explicit action often don't work, see Bug 1960237.
      form.hasAttribute("action") &&
      // The only other method is dialog.
      (method == "GET" || method == "POST") &&
      // The other methods are post and dialog.
      // Post forms are rarely search forms, see discussion in Bug 1964507.
      // Dialog forms are not supported for obvious reasons.
      method == "GET" &&
      // SearchEngine objects currently only support urlencoded requests.
      form.enctype == "application/x-www-form-urlencoded" &&
      // Don't allow forms with file inputs.