Skip to content

Commit

Permalink
[fix] parse: with comma true, do not split non-string values
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Omar authored and ljharb committed Oct 4, 2019
1 parent 670254b commit 698b683
Show file tree
Hide file tree
Showing 2 changed files with 15 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 @@ -83,7 +83,7 @@ var parseValues = function parseQueryStringValues(str, options) {
val = interpretNumericEntities(val);
}

if (val && options.comma && val.indexOf(',') > -1) {
if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
val = val.split(',');
}

Expand Down
14 changes: 14 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,20 @@ test('parse()', function (t) {
st.end();
});

t.test('use number decoder, parses string that has one number with comma option enabled', function (st) {
var decoder = function (str, defaultDecoder, charset, type) {
if (!isNaN(Number(str))) {
return parseFloat(str);
}
return defaultDecoder(str, defaultDecoder, charset, type);
};

st.deepEqual(qs.parse('foo=1', { comma: true, decoder: decoder }), { foo: 1 });
st.deepEqual(qs.parse('foo=0', { comma: true, decoder: decoder }), { foo: 0 });

st.end();
});

t.test('parses an object in dot notation', function (st) {
var input = {
'user.name': { 'pop[bob]': 3 },
Expand Down

0 comments on commit 698b683

Please sign in to comment.