mirror of
https://github.com/avwo/whistle.git
synced 2026-10-19 07:01:44 +08:00
36 lines
778 B
JavaScript
36 lines
778 B
JavaScript
var qs = require('querystring');
|
|
|
|
var TOKEN_RE = /\r\u0000\n\u0003\r/g;
|
|
var PLUS_RE = /\+/g;
|
|
var TOKEN = '\r\u0000\n\u0003\r';
|
|
|
|
var decoder = {
|
|
decodeURIComponent: function (s) {
|
|
s = s.replace(TOKEN_RE, '+');
|
|
return qs.unescape(s);
|
|
}
|
|
};
|
|
var rawDecoder = {
|
|
decodeURIComponent: function (s) {
|
|
return s.replace(TOKEN_RE, '+');
|
|
}
|
|
};
|
|
var rawDecoder2 = {
|
|
decodeURIComponent: function (s) {
|
|
return s;
|
|
}
|
|
};
|
|
|
|
function parse(str, sep, eq, escape) {
|
|
try {
|
|
if (str.indexOf('+') === -1 || str.indexOf(TOKEN) !== -1) {
|
|
return qs.parse(str, sep, eq, escape ? rawDecoder2 : undefined);
|
|
}
|
|
str = str.replace(PLUS_RE, TOKEN);
|
|
return qs.parse(str, sep, eq, escape ? rawDecoder : decoder);
|
|
} catch (e) {}
|
|
return '';
|
|
}
|
|
|
|
module.exports = parse;
|