2022-02-13 17:06:35 -05:00
|
|
|
"use strict";
|
|
|
|
|
2016-03-12 13:50:43 -05:00
|
|
|
function decode(encoded) {
|
|
|
|
var result = "";
|
|
|
|
for (var i = 0; i < encoded.length; i++) {
|
|
|
|
var c = encoded[i];
|
|
|
|
if (c == "+") {
|
|
|
|
result += " ";
|
|
|
|
} else if (c == "%") {
|
|
|
|
result += String.fromCharCode(parseInt(encoded.slice(i + 1, i + 3), 16));
|
|
|
|
i += 2;
|
|
|
|
} else {
|
|
|
|
result += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function decodeForm(encoded, initial) {
|
|
|
|
var result = initial || {};
|
|
|
|
if (encoded) {
|
|
|
|
encoded = encoded.trim();
|
|
|
|
var items = encoded.split('&');
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
var item = items[i];
|
|
|
|
var equals = item.indexOf('=');
|
|
|
|
var key = decode(item.slice(0, equals));
|
|
|
|
var value = decode(item.slice(equals + 1));
|
|
|
|
result[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.decodeForm = decodeForm;
|