You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Any way to bypass querystring.stringify with empty Object ? #12234
The problem is for Object (probably also for empty array) such as
{ "extendTypes":{} }
is serialiazed as :
extendTypes=
The expected result :
extendTypes={}
or its URI encoded version :
extendTypes%3D%7B%7D
So , how can I ever hope to do that ? Any way to bypass this default behalvior ?
Here is my full code if you want :
function generateGetRequest(dataMap, url) {
let queryParams = {};
let uriParams = {};
for (let [key, value] of dataMap) {
// if value is an object or an array
if (value instanceof Object || value instanceof Array) {
uriParams[key] = value;
} else {
// param working for superagent
queryParams[key] = value;
}
}
let queryParamsUri = querystring.stringify(uriParams);
console.log(queryParamsUri);
let finalUrl = url + ( (Object.keys(uriParams).length > 0) ? "?" + queryParamsUri : "");
}
changed the title [-]NodeJs querystring.stringify not working with Object[/-][+]Any way to bypass querystring.stringify with empty Object[/+]on Apr 5, 2017
changed the title [-]Any way to bypass querystring.stringify with empty Object[/-][+]Any way to bypass querystring.stringify with empty Object ?[/+]on Apr 5, 2017
I believe the behavior of querystring.stringify() is absolutely correct and it produces the result I'd expect it to, but I agree that the documentation may be improved.
I agree with you about the documentation. As least , why not provide a list of value that will not be seriliazed ? I don't think there are so many cases
For example :
Yeah it's more like a doc issue. Though I think this should be a list of values that will be serialized instead of values that will not be serialized? (logic is in
Activity
[-]NodeJs querystring.stringify not working with Object[/-][+]Any way to bypass querystring.stringify with empty Object[/+][-]Any way to bypass querystring.stringify with empty Object[/-][+]Any way to bypass querystring.stringify with empty Object ?[/+]aqrln commentedon Apr 5, 2017
https://github.com/nodejs/help, https://gitter.im/nodejs/node and #node.js channel on IRC are better places to ask such questions. FWIW, you probably want to pass a JSON string as the value of
extendTypes.I believe the behavior of
querystring.stringify()is absolutely correct and it produces the result I'd expect it to, but I agree that the documentation may be improved.jy95 commentedon Apr 5, 2017
I agree with you about the documentation. As least , why not provide a list of value that will not be seriliazed ? I don't think there are so many cases
For example :
joyeecheung commentedon Apr 10, 2017
Yeah it's more like a doc issue. Though I think this should be a list of values that will be serialized instead of values that will not be serialized? (logic is in
node/lib/querystring.js
Lines 219 to 268 in cfc8422
Labeld as good first contribution. Feel free to send in a doc PR.
shubheksha commentedon Apr 10, 2017
Can I take this up?
addaleax commentedon Apr 10, 2017
@shubheksha Go for it! Let us know if you need any help. :)
jy95 commentedon Apr 10, 2017
@shubheksha thanks.
refack commentedon Jul 19, 2017
Closed by #12313