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

Does Not Parse Boolean/Number in array #420

Open
meilechwieder opened this issue Aug 27, 2021 · 6 comments
Open

Does Not Parse Boolean/Number in array #420

meilechwieder opened this issue Aug 27, 2021 · 6 comments

Comments

@meilechwieder
Copy link

Consider this code

Qs.stringify({
  field: {
      $in: [true, false,0,1]
  }
})

true, false, 0, 1 all become strings

@ljharb
Copy link
Owner

ljharb commented Aug 27, 2021

As they should, since query strings in the browser (like the entire URL) is always and only a string.

The method is named "stringify" - do you expect something different?

@meilechwieder
Copy link
Author

meilechwieder commented Aug 27, 2021 via email

@ljharb
Copy link
Owner

ljharb commented Aug 27, 2021

parse is expected to produce something that's not a string, but stringify is not.

Separately, qs.parse does not in fact do that in my testing:

qs.parse('true') // { true: '' }
qs.parse('a=true') // { a: 'true' }

etc.

@dmitry
Copy link

dmitry commented Sep 15, 2021

@dmitry
Copy link

dmitry commented Sep 15, 2021

BTW #91

@ljharb
Copy link
Owner

ljharb commented Sep 15, 2021

@dmitry that's because parse only accepts a string. Passing a boolean in is a type error, something that I'll probably make throw an exception in the next semver-major, whenever that is.

Regarding #91, a=true in a query string is the string "true", not a boolean, so qs won't ever do the wrong thing there by default. You'll have to use a custom decoder if you want nonstandard types.

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

No branches or pull requests

3 participants