Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 14 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,18 @@ 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');

obj = qs.parse('foo+bar=baz%2Bqux');

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