Bug 620565 - Proper handling of question mark in the action field of a form when creating a search keyword bookmark. r=MattN
authorIaroslav Sheptykin <yarik.sheptykin@googlemail.com>
Thu, 18 Sep 2014 13:54:04 -0700
changeset 206143 87b3c243b7644be4942b2d2dbab17f561b03209c
parent 206142 43b24197d25adaf2030e7b5ce1ea5fa0bdfbc820
child 206144 a660e08ac3b2a1a0d43fdade0a57e22a86a481d6
push id27514
push usercbook@mozilla.com
push dateFri, 19 Sep 2014 12:24:09 +0000
treeherdermozilla-central@3475e6a1665a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs620565
milestone35.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 620565 - Proper handling of question mark in the action field of a form when creating a search keyword bookmark. r=MattN
browser/base/content/browser.js
browser/base/content/test/general/browser_addKeywordSearch.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6073,18 +6073,20 @@ function GetSearchFieldBookmarkData(node
       }
     }
   }
 
   var postData;
 
   if (isURLEncoded)
     postData = formData.join("&");
-  else
-    spec += "?" + formData.join("&");
+  else {
+    let separator = spec.contains("?") ? "&" : "?";
+    spec += separator + formData.join("&");
+  }
 
   return {
     spec: spec,
     title: title,
     description: description,
     postData: postData,
     charSet: charset
   };
--- a/browser/base/content/test/general/browser_addKeywordSearch.js
+++ b/browser/base/content/test/general/browser_addKeywordSearch.js
@@ -29,16 +29,18 @@ function test() {
       doc.body.removeChild(form);
     }
 
     let testData = [
     /* baseURI, field name, expected */
       [ 'http://example.com/', 'q', 'http://example.com/?q=%s' ],
       [ 'http://example.com/new-path-here/', 'q', 'http://example.com/new-path-here/?q=%s' ],
       [ '', 'q', 'http://example.org/browser/browser/base/content/test/general/dummy_page.html?q=%s' ],
+      // Tests for proper behaviour when called on a form whose action contains a question mark.
+      [ 'http://example.com/search?oe=utf-8', 'q', 'http://example.com/search?oe=utf-8&q=%s' ],
     ]
 
     for (let data of testData) {
       check(data[0], data[1], data[2]);
     }
 
     // cleanup
     gBrowser.removeCurrentTab();