http: smarter handling of decodeURIComponent calls.

This commit is contained in:
Christopher Jeffrey 2017-07-20 17:18:18 -07:00
parent a915545a1a
commit 6a7c5eac8d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 22 additions and 8 deletions

View File

@ -251,9 +251,16 @@ function parsePairs(str) {
} }
function unescape(str) { function unescape(str) {
str = decodeURIComponent(str); try {
str = str.replace(/\+/g, ' '); str = decodeURIComponent(str);
str = str.replace(/\0/g, ''); str = str.replace(/\+/g, ' ');
} catch (e) {
throw new Error('Malformed URI.');
}
if (str.indexOf('\0') !== -1)
throw new Error('Malformed URI.');
return str; return str;
} }

View File

@ -1654,8 +1654,12 @@ function parsePairs(str, limit) {
} }
function unescape(str) { function unescape(str) {
str = decodeURIComponent(str); try {
str = str.replace(/\+/g, ' '); str = decodeURIComponent(str);
str = str.replace(/\+/g, ' ');
} catch (e) {
;
}
str = str.replace(/\0/g, ''); str = str.replace(/\0/g, '');
return str; return str;
} }

View File

@ -923,10 +923,13 @@ Config.prototype.parseForm = function parseForm(query, map) {
function unescape(str) { function unescape(str) {
try { try {
str = decodeURIComponent(str).replace(/\+/g, ' '); str = decodeURIComponent(str);
} finally { str = str.replace(/\+/g, ' ');
return str.replace(/\0/g, ''); } catch (e) {
;
} }
str = str.replace(/\0/g, '');
return str;
} }
function isAlpha(str) { function isAlpha(str) {