Skip to content

Commit

Permalink
allow object keys that start with a number, closes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Sep 18, 2014
1 parent af9406c commit 9f3e810
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ internals.parseObject = function (chain, val, options) {
else {
var cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
var index = parseInt(cleanRoot, 10);
var indexString = '' + index;
if (!isNaN(index) &&
root !== cleanRoot &&
indexString === cleanRoot &&
index <= options.arrayLimit) {

obj = [];
Expand Down
6 changes: 6 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ describe('#parse', function () {
done();
});

it('supports keys that begin with a number', function (done) {

expect(Qs.parse('a[12b]=c')).to.deep.equal({ a: { '12b': 'c' } });
done();
});

it('supports encoded = signs', function (done) {

expect(Qs.parse('he%3Dllo=th%3Dere')).to.deep.equal({ 'he=llo': 'th=ere' });
Expand Down

0 comments on commit 9f3e810

Please sign in to comment.