-
-
Notifications
You must be signed in to change notification settings - Fork 735
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
Stringifying using different arrayFormats, then parsed, create different things #345
Comments
Having the same issues here. Is there any update on this? |
It's entirely reasonable that the same string produces different results when you use different array formats. In this case, it seems like "brackets" does have a bug, whether in stringify, parse, or both. |
judging from other query string libraries, it might require specifying the arrayFormat in both stringify and parse |
ohhhh right, it absolutely does :-) i missed that. @wholien what happens if you specify |
@ljharb doing it with
I was reading through the readme and some of the |
Seems like we do have an issue here then. I agree with the general premise that for any format Happy to accept a PR here, but I'm not sure concretely what it should change. Failing test cases are probably the best place to start! |
On the most recent version, an array stringified and parsed returns a string:
where as previously an array is returned:
|
@nigeldunne in this case, I'd say the issue is that |
@ljharb sounds reasonable. I think the key is your point about the ability to do a "round trip". |
Fixed in #361, I think? |
@ljharb The "round trip" still does not work when arrayFormat is "comma":
|
@nigeldunne thanks, reopening |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For now, I use this solution qs.parse(str, {
comma: true,
decoder(str, defaultDecoder, charset, type) {
const decoded = defaultDecoder(str);
if (type === "value" && typeof decoded === "string" && decoded.includes(",")) {
return decoded.split(",");
}
return decoded;
},
}) probably not the best solution but it is working for my case. |
It seems stringifying my
metadata
object witharrayFormat: brackets
, then parsing it, creates a different object to stringifying witharrayFormat: indices
then parsing that string.Am I doing something wrong? Is this expected? Is this just an issue with stringifying/parsing nested objects?
The text was updated successfully, but these errors were encountered: