Skip to content

Commit

Permalink
[fix] Convert plus signs to spaces
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
lpinca committed Jan 23, 2017
1 parent b206ebd commit 62b706d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

var has = Object.prototype.hasOwnProperty;

/**
* Decode a URI encoded string.
*
* @param {String} input The URI encoded string.
* @returns {String} The decoded string.
* @api private
*/
function decode(input) {
return decodeURIComponent(input).replace(/\+/g, ' ');
}

/**
* Simple query string parser.
*
Expand All @@ -21,7 +32,7 @@ function querystring(query) {
//
for (;
part = parser.exec(query);
result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
result[decode(part[1])] = decode(part[2])
);

return result;
Expand Down
11 changes: 9 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('querystringify', function () {

it('works with object keys with empty string values', function () {
assume(qs.stringify({ foo: '' })).equals('foo=');
})
});

it('works with nulled objects', function () {
var obj = Object.create(null);
Expand Down Expand Up @@ -70,6 +70,13 @@ describe('querystringify', function () {
assume(obj.foo).equals('');
assume(obj.bar).equals('');
assume(obj.shizzle).equals('mynizzle');
})
});

it('decodes plus signs', function () {
var obj = qs.parse('foo+bar=baz+qux');

assume(obj).is.a('object');
assume(obj['foo bar']).equals('baz qux');
});
});
});

0 comments on commit 62b706d

Please sign in to comment.