diff --git a/lib/querystring.js b/lib/querystring.js index 4246e96..f770013 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -47,7 +47,7 @@ exports.parse = function(str){ try{ pair = decodeURIComponent(pair.replace(/\+/g, ' ')); } catch(e) { - // ignore + pair = unescape(pair.replace(/\+/g, ' ')); } var eql = pair.indexOf('=') diff --git a/test/parse.test.js b/test/parse.test.js index 4e7d730..d724cc0 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -140,8 +140,13 @@ module.exports = { 'test malformed uri': function(){ qs.parse('{%:%}').should.eql({ '{%:%}': '' }); qs.parse('foo=%:%}').should.eql({ 'foo': '%:%}' }); + qs.parse('foo=%:%}%20').should.eql({ 'foo': '%:%} ' }); + }, + + 'test unescaping of non-utf8 encoded data': function(){ + qs.parse('foo=%E4%20bar').should.eql({ 'foo': String.fromCharCode('228') + ' bar' }); } - + // 'test complex': function(){ // qs.parse('users[][name][first]=tj&users[foo]=bar') // .should.eql({