From eede68dc61dd8924260727a950e146c39de94070 Mon Sep 17 00:00:00 2001 From: Arshad Kazmi Date: Tue, 18 Dec 2018 23:44:15 +0000 Subject: [PATCH] Bug 1365542 - Use HTML5 FormData object rather than hand-rolling form data for search keyword handling r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D14877 --HG-- extra : moz-landing-system : lando --- browser/actors/ContextMenuChild.jsm | 35 +++++------------------------ 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/browser/actors/ContextMenuChild.jsm b/browser/actors/ContextMenuChild.jsm index 02c99eebedbd..eb865d6c8973 100644 --- a/browser/actors/ContextMenuChild.jsm +++ b/browser/actors/ContextMenuChild.jsm @@ -125,41 +125,18 @@ const messageListeners = { (node.form.enctype == "application/x-www-form-urlencoded" || node.form.enctype == "")); let title = node.ownerDocument.title; - let formData = []; - function escapeNameValuePair(aName, aValue, aIsFormUrlEncoded) { - if (aIsFormUrlEncoded) { + function escapeNameValuePair([aName, aValue]) { + if (isURLEncoded) { return escape(aName + "=" + aValue); } return escape(aName) + "=" + escape(aValue); } - - for (let el of node.form.elements) { - if (!el.type) // happens with fieldsets - continue; - - if (el == node) { - formData.push((isURLEncoded) ? escapeNameValuePair(el.name, "%s", true) : - // Don't escape "%s", just append - escapeNameValuePair(el.name, "", false) + "%s"); - continue; - } - - let type = el.type.toLowerCase(); - - if (((el instanceof this.content.HTMLInputElement && el.mozIsTextField(true)) || - type == "hidden" || type == "textarea") || - ((type == "checkbox" || type == "radio") && el.checked)) { - formData.push(escapeNameValuePair(el.name, el.value, isURLEncoded)); - } else if (el instanceof this.content.HTMLSelectElement && el.selectedIndex >= 0) { - for (let j = 0; j < el.options.length; j++) { - if (el.options[j].selected) - formData.push(escapeNameValuePair(el.name, el.options[j].value, - isURLEncoded)); - } - } - } + let formData = new this.content.FormData(node.form); + formData.delete(node.name); + formData = Array.from(formData).map(escapeNameValuePair); + formData.push(escape(node.name) + (isURLEncoded ? escape("=%s") : "=%s")); let postData;