URI.js
URI.js copied to clipboard
Always add an equal sign for empty values in the query string
https://github.com/medialize/URI.js/blob/gh-pages/src/URI.js#L739
I read this comment about having =
for null values in the source, then read the referenced spec, but got to the opposite conclusion: you should output a =
for all values including null
s.
Am I reading the spec wrong or missing something here?
Append name, followed by U+003D (=), followed by value, to output.
https://url.spec.whatwg.org/#urlencoded-serializing
This comment suggests that at some point the URL spec said something different than it does now. These days it looks as if the value should be the empty string regardless of =
being there or not. HTML5 URL-encoded form data agrees with the URL spec.
Are you up for a PR to tackle this?
I'm not really concluded on whether I would, personally, like the =
or not.
I would like to do some research into whether parsers (and the spec for it) are fine with not having it for empty values, and if so, I would probably prefer it to be omitted.
Regarding a pull request, I am not a fan of the approach of this library (doing everything itself - no dependencies), so I've built https://github.com/srcagency/http-querystring-stringify and filed the issue here during research for it. I thought it would be of use here. So I'm not really motivated for the work to be honest.
fair enough! thank you for the heads up :)
What sets your module apart from querystring (browser version of node querystring) and qs?
A lot, I'm afraid. Unfortunately there are so many ways to do this (mostly the part of going from JS types to strings), that I doubt you can have one universal.
First of all I wanted to split encoding and decoding as my projects tend to use one or the other, and they are very different to implement.
From the README of https://github.com/srcagency/http-querystring-stringify:
toJSON
is respected (likeJSON.stringify
does)true
andfalse
are converted toy
orn
respectivelynull
is represented by an empty stringundefined
values will be skipped completely- arrays will be numbered only if they contain arrays or objects themselves
Depending on my research on =
, the next difference may be that empty strings do not carry the =
(I think that's cleaner).
This inspired me to add a "compatibility" section with a list of parsers: https://github.com/srcagency/http-querystring-stringify#compatibility-with-parsers