Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Make stringQs ignore empty arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Apr 29, 2013
1 parent 4097799 commit 5bf42ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -14,7 +14,9 @@ ohauth.qsString = function(obj) {
};

ohauth.stringQs = function(str) {
return str.split('&').reduce(function(obj, pair){
return str.split('&').filter(function (pair) {
return pair !== '';
}).reduce(function(obj, pair){
var parts = pair.split('=');
obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?
'' : decodeURIComponent(parts[1]);
Expand Down
4 changes: 4 additions & 0 deletions test/ohauth.js
Expand Up @@ -20,6 +20,10 @@ describe('ohauth', function() {
it('handles special characters', function() {
expect(ohauth.stringQs('%21%27%2A%28%29=%21%27%2A%28%29')).to.eql({ "!'*()": "!'*()" });
});
it('handles querystrings with empty arguments', function() {
expect(ohauth.stringQs('')).to.eql({});
expect(ohauth.stringQs('foo=1&')).to.eql({ foo: 1 });
});
});

describe('#nonce', function() {
Expand Down

0 comments on commit 5bf42ac

Please sign in to comment.