ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.52k stars 731 forks source link

ignoreQueryPrefix should be true by default #283

Open Kepro opened 6 years ago

Kepro commented 6 years ago

it will be a big benefit if ignoreQueryPrefix will be true by default :)

for example with usage with react-router -> location.search is with "?"

ljharb commented 6 years ago

you can do location.search.slice(1).

This would be a breaking change, and I'm not sure it's really worth it.

jalik commented 3 years ago

Since the issue is still open, would you reconsider handling this issue ?

The question is: why someone would need to get "?arg" instead of "arg" ? When you parse the query params, you never want to get the "?" with the parameter.

Usually most if not all people do that :

  1. Get query string from location.search
  2. Remove the first character (?)
  3. Parse the string to get an object

By changing ignoreQueryPrefix it to true by default, you would just remove the need of the step 2. I may be wrong, but in which case does someone would need to get "?" with the parameter ?

ljharb commented 3 years ago

While I agree that it's likely nobody is relying on this functionality, semver is about theoretical breakage, not about actual breakage, and it would be improper to include an obvious potentially breaking change in a non-major version.

jalik commented 3 years ago

@ljharb obviously if you change the default behavior, it would involve releasing a new major version, I just don't get why you don't want to do that (just trying to understand). Another point is that if you release a major version, npm update will not upgrade automatically the package, so developers should not encounter breaking problems, they could choose to upgrade it manually.

I was expecting this kind of answer (you're the author, you have your reasons, no problem), so I have installed query-string instead which is working like I expect it to, but I would have preferred to keep with qs because i use express and it is shipped with.

Thank you for your time.

ljharb commented 3 years ago

It's pretty easy to make your own package that does (value, opts = {}) => qs.stringify(value, { ...opts, ignoreQueryPrefix: true })), so I'm not sure why you'd need to use another package for that, especially one that doesn't support older browsers or nodes.

Major versions are very costly, primarily for the reasons you mention. Surely when I release a major version, I'll default this param to true, but that alone is a pretty poor reason to create ecosystem churn.

ptolemybarnes commented 1 year ago

I would second a breaking change to make this the default. It's quite surprising that the "?" is included and I can't think of a scenario in which that would be useful.

Also, is "?" actually part of the query string? At least according to wikipedia it's not, and looking at the schema diagram on the RFC it seems not.