Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayFormat Type Comma is producing the output of Array Format Repeat when the array length is 1 #442

Closed
manoj-rp opened this issue Jun 9, 2022 · 13 comments

Comments

@manoj-rp
Copy link

manoj-rp commented Jun 9, 2022

qs.stringify({ a: ['b'] }, { arrayFormat: 'comma' }) should return the a=b.

But it is returning the repeat type format - a%5B%5D=b ~ a[]=b

Below is the documentation and expected behaviour from readme

qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 'a=b,c'

Below is the screenshot for the same

image

Can anyone help me if this is an issue or Am I missing something?

@goodrick
Copy link

goodrick commented Jun 9, 2022

I encountered the same problem. I locked version 6.9.6

@manoj-rp
Copy link
Author

manoj-rp commented Jun 9, 2022

Thanks for your reply. Unfortunately this module is being used by some other module. And I'm using that module for my usecase.

@ljharb
Copy link
Owner

ljharb commented Jun 9, 2022

This isn’t a bug, it is intentional behavior so that stringifying will preserve the array-ness.

@ljharb
Copy link
Owner

ljharb commented Jun 9, 2022

See #434

@manoj-rp
Copy link
Author

manoj-rp commented Jun 10, 2022

I have read the thread. But Shouldn't it be configurable?

Can we have another option along with arrayType.

preserveArrayness: true/false

Because there can be usecases like

One can use qs for stringifying it and may not be using it for parsing back again?

In our case,

We stringify it and pass the query string to an external service and that service doesn't use the qs module to parse it back?

Any thoughts @ljharb

@mima0815
Copy link

we run into the same issue with the new version.

not all APIs we are using are capable to handling query strings with brackets, they are expecting comma separated lists in all cases or no comma if it is only one value.

+1 for the additional option to toggle the "Arrayness" feature.

@glomotion
Copy link

glomotion commented Jun 15, 2022

we have also just slammed into this issue. Tis causing a great deal of errors in production for us right now (we use QS to stringify params which are sent to an API - which does NOT support array bracket query string notation). 😭

for now, we'll just lock to 6.9.6 like the suggestion above.

@Shooz136
Copy link

Same here - I'd appreciate a configurable option.

@ljharb
Copy link
Owner

ljharb commented Jun 15, 2022

I will plan on reverting the behavior by default, and adding an option to satisfy the original request.

@manoj-rp
Copy link
Author

manoj-rp commented Jun 15, 2022 via email

@chengwb53
Copy link

chengwb53 commented Jun 17, 2022

debug find this:
image
array.length === 1 use brackets

lock version

@lpillonel

This comment was marked as spam.

@ljharb ljharb closed this as completed in c313472 Jun 27, 2022
@ljharb
Copy link
Owner

ljharb commented Jun 27, 2022

Released in v6.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants