-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Send undefined query #1481
Comments
Can we get a confirmation on whether or not this is a bug or expected behavior? This can have all sorts of downstream consequences, so we have pinned this package to 4.x for now. I'm trying to decide if this is the responsibility of the caller, in which case we'll need to address it across our services, or if we should wait for a fix. One data point is that this new behavior does not have parity with const qs = { a: undefined, b: 1 };
JSON.stringify(qs); // "{"b":1}" Note that the result has the key whose value is |
The current behaviour in Node and browsers is different. +1 for retaining backward compatible(omit undefined fields). |
The node implementation uses qs.stringify({ a: null, b: undefined }) //=> 'a=' The browser implementation(v4) behaves exactly the same with function pushEncodedKeyValuePair(pairs, key, val) {
if (val != null) {
// push value to paires
} else if (val === null) {
pairs.push(encodeURIComponent(key));
}
} v5 changes the first condition: function pushEncodedKeyValuePair(pairs, key, val) {
- if (val != null) {
+ if (val !== null) {
// push value to paires
} else if (val === null) {
pairs.push(encodeURIComponent(key));
}
} It looks like a unintentional change(to conform with eslint maybe) to me. 👇 I created a PR to fix this by omitting |
v5 fails the browser tests due to ladjs/superagent#1481
This is preventing me from upgrading to v5, sticking with v4 for now. |
const qs = { a: undefined, b: 1 };
request.get('my-url').query(qs).end();
// version 4.1.0
send my-url?b=1
// version 5.0.2
send my-url?a=undefined&b=1
I tested it on chrome 73.0.3683.103
The text was updated successfully, but these errors were encountered: