ljharb/qs

Stringify with `comma` format should add square brackets to parameter name to identity array with single value

开放

#315 创建于 2019年6月4日

 (17 条评论) (5 个反应) (0 位负责人)JavaScript (903 个派生)batch import
enhancementhelp wantedstringify

仓库指标

星标
 (8,943 个星标)
PR 合并指标
 (平均合并 6天 22小时) (30 天内合并 2 个 PR)

描述

Hi. With new comma array format, stringify of array with single value will produce following result:

const options = {
    arrayFormat: 'comma'
};
qs.stringify({foo: [1]}, options); // foo=1
qs.stringify({foo: [1, 2]}, options); // foo=1,2

So, on parse stage, parsing will produce single value.

qs.parse('foo=1); // {foo: 1}
qs.parse('foo=1,2'); // {foo: [1, 2]}

Maybe add square brackets to parameter name, when comma array format is used?

qs.stringify({foo: [1]}, options); // foo[]=1
qs.stringify({foo: [1, 2]}, options); // foo[]=1,2
qs.parse('foo[]=1); // {foo: [1]}
qs.parse('foo[]=1,2'); // {foo: [1, 2]}

Currently, parsing of the following query string foo[]=1,2 working as expected

贡献者指南