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

array values are not parsing properly as per the documentation #214

Closed
ramsane opened this issue Aug 7, 2021 · 3 comments
Closed

array values are not parsing properly as per the documentation #214

ramsane opened this issue Aug 7, 2021 · 3 comments
Labels

Comments

@ramsane
Copy link

ramsane commented Aug 7, 2021

There is this line where we are parsing the custom params payload with encode: false. However, if we pass an array, it won't stringy properly. For this, we need to pass an extra parameter.

var qs = require("qs")
qs.stringify({'a':'asdf', 'b': ['a','b']}, {encode: false, arrayFormat: 'comma'})

will produce the output "a=asdf&b=a,b" as intended.

But the current code only has encode: false as an option. Without the arrayFormat, we will get output something like this.

var qs = require("qs")
qs.stringify({'a':'asdf', 'b': ['a','b']}, {encode: false})

Output: "a=asdf&b[0]=a&b[1]=b"

link: https://github.com/robsontenorio/vue-api-query/blob/dev/src/Parser.js#L155

Hope the problem is clear.

@ramsane ramsane changed the title array values are not parsing propery as per the documentation array values are not parsing properly as per the documentation Aug 7, 2021
@ramsane
Copy link
Author

ramsane commented Aug 7, 2021

For now, I can make that string manually with status: ['first', 'second'].join(',') to make the string status=first,second manually. But I think this should be updated in the code.

@github-actions
Copy link

github-actions bot commented Jul 5, 2022

🎉 This issue has been resolved in version 1.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Versleijen
Copy link

Versleijen commented Aug 12, 2022

Hi,

First, thank you for the great work put in vue-api-query!
We are using vue-api-query for some time now and we are running into problems caused by this change.
Our backend (Laravel, PHP) can handle the old way ("a=asdf&b[0]=a&b[1]=b") of parsing the array values out of the box. For the new way ("a=asdf&b=a,b") we need to make changes the get an array.

In my opinion the old way ("a=asdf&b[0]=a&b[1]=b") is more supported in backend frameworks. At least we should have the option to choose which formatting we would want to use. Or is there an easier way to make this work for Laravel?
See also this discussion on StackOverflow: https://stackoverflow.com/questions/6243051/how-to-pass-an-array-within-a-query-string

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

No branches or pull requests

2 participants