1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-17 03:15:45 +01:00

Automagically grab form charset in ;S.

This commit is contained in:
Kris Maglione
2011-01-09 15:36:10 -05:00
parent a2e6e655c7
commit 3485424f6e
7 changed files with 87 additions and 35 deletions

View File

@@ -1070,21 +1070,35 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
// Nuances gleaned from browser.jar/content/browser/browser.js
parseForm: function parseForm(field) {
function encode(name, value, param) {
if (param)
value = value + "%s";
if (post)
return name + "=" + value;
return encodeURIComponent(name) + "=" + (param ? value : encodeURIComponent(value));
param = param ? "%s" : "";
if (post) // Seems wrong.
return encodeComponent(name + "=" + value + param);
return encodeComponent(name) + "=" + encodeComponent(value) + param;
}
let form = field.form;
let doc = form.ownerDocument;
let charset = doc.charset;
let charset = doc.characterSet;
let converter = services.CharsetConv(charset);
for each (let cs in form.acceptCharset.split(/\s*,\s*|\s+/)) {
let c = services.CharsetConv(cs);
if (c) {
converter = services.CharsetConv(cs);
charset = cs;
}
}
let uri = util.newURI(doc.baseURI.replace(/\?.*/, ""), charset);
let url = util.newURI(form.action, charset, uri).spec;
let post = form.method.toUpperCase() == "POST";
let encodeComponent = encodeURIComponent;
if (charset !== "UTF-8")
encodeComponent = function encodeComponent(str)
escape(converter.ConvertFromUnicode(str) + converter.Finish());
let elems = [];
if (field instanceof Ci.nsIDOMHTMLInputElement && field.type == "submit")
elems.push(encode(field.name, field.value));
@@ -1101,8 +1115,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}
}
if (post)
return [url, elems.map(encodeURIComponent).join('&'), elems];
return [url + "?" + elems.join('&'), null];
return [url, elems.join('&'), elems, charset];
return [url + "?" + elems.join('&'), null, charset];
},
/**