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

Issue for ISO 8601 dates on arrayFormat separator option #242

Closed
jessedobbelaere opened this issue Feb 20, 2020 · 4 comments · Fixed by #287
Closed

Issue for ISO 8601 dates on arrayFormat separator option #242

jessedobbelaere opened this issue Feb 20, 2020 · 4 comments · Fixed by #287

Comments

@jessedobbelaere
Copy link

jessedobbelaere commented Feb 20, 2020

On v6.10.1 we were succesfully parsing the following two url params using the comma parser:

parse(queryString, { arrayFormat: "comma", parseBooleans: true, parseNumbers: true });
// Request: id%28in%29=992232%2C992237%2C992240
// Parsed: 
// {
//    id(in): [992232, 992237, 992240],
// }

// Request: timestamp_begin(gte)=2020-01-01T00:00:00%2B03:00
// Parsed: 
// {
//     timestamp_begin(gte): "2020-01-01T00:00:00+03:00"
// }

Here, our ISO 8601 datetime is not getting modified ✅ .

However, with the release of v6.11.0, we ran into issues because of the encoded commas that are passed to our API, due to the change of (#236).
After switching to the arrayFormat "separator" we seem to get the old behaviour from v6.10.1 with our encoded comma arrays, except for one issue with our ISO 8601 DateTime.

parse(queryString, { arrayFormat: "separator", parseBooleans: true, parseNumbers: true });
// Request: id%28in%29=992232%2C992237%2C992240
// Parsed: 
// {
//    id(in): [992232, 992237, 992240],
// }
// This works great again

// Request: timestamp_begin(gte)=2020-01-01T00:00:00%2B03:00
// Parsed: 
// {
//     timestamp_begin(gte): "2020-01-01T00:00:00 03:00"
// }
// Here the + sign is removed from our datetime string

Note: when switching it to arrayFormat: "comma" again the datetime is correct (+ sign not removed. (But we cannot use the comma format because of our encoded comma's in the requests we get.)

Made a small code sample to illustrate: https://stackblitz.com/edit/typescript-udk9sb (open console)

@sindresorhus
Copy link
Owner

// @cheqianxiao

@jessedobbelaere
Copy link
Author

hi @cheqianxiao, do you know if there will be a fix in the future? Or if there is a workaround for:

#243 (comment)

As the PR fixed the issue partially

@cheqianxiao
Copy link
Contributor

cheqianxiao commented Aug 21, 2020

@jessedobbelaere hey~ you can try this workaround for that issue:

parse(decodeURIComponent(queryString), { arrayFormat: "comma", parseBooleans: true, parseNumbers: true });

and... sorry, I don't know if there will be a fix in the future.

@jessedobbelaere
Copy link
Author

Thanks @cheqianxiao ! Unfortunately, using decodeURIComponent(queryString) then I have the same issue again as my original post about ISO 8601 dates (+ sign removed):

image

While on v6.10.1 things were still working. I guess if I want to upgrade to the latest query-string version I could do a hacky approach to only decode the comma's 😅: With this approach all my unit tests still succeed on the latest query-string package version.

const queryObject = parse(queryString.replace(/%2C/g, ","), {
    arrayFormat: "comma",
    parseBooleans: true,
    parseNumbers: true,
});

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

Successfully merging a pull request may close this issue.

3 participants