Skip to content

Commit

Permalink
allow parsing partially parsed objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jul 31, 2014
1 parent 8d8ad61 commit 6667340
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = function (str, depth) {
return {};
}

var tempObj = internals.parseValues(str);
var tempObj = typeof str === 'string' ? internals.parseValues(str) : Utils.clone(str);
var obj = {};

// iterate over the keys and setup the new object
Expand Down
7 changes: 7 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,11 @@ describe('Riddler.parse()', function () {
expect(Riddler.parse('a[9999]=1&a[2]=2')).to.deep.equal({ a: ['2', '1'] });
done();
});

it('parses semi-parsed strings', function (done) {

expect(Riddler.parse({ 'a[b]': 'c' })).to.deep.equal({ a: { b: 'c' } });
expect(Riddler.parse({ 'a[b]': 'c', 'a[d]': 'e' })).to.deep.equal({ a: { b: 'c', d: 'e' } });
done();
});
});

0 comments on commit 6667340

Please sign in to comment.