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 }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
url.format (on node 0.12.0, which in turn calls querystring.stringify) will include parameters on an object that are explicitly undefined. If you don't want to read the real life consequences, here's some example code demonstrating the issue - just skip to the bottom.
If I do not pass in freeToPlayOnly to all(), then obviously it will be undefined. The object passed to riot.get will, therefore, be { freeToPlay: undefined }. Inside riot.get, the following code is invoked:
functionget(region,version,path,queryParameters){varmyUrl=url.format({host: util.format(base,region),protocol: 'http',pathname: util.format(pathFormat,region,version,path),query: queryParameters});// the following is example codereturnhttp.get(myUrl);}
As you can see from the above code, our { freeToPlay: undefined } is passed to the get function as queryParameters, which are then passed to query.
If you invoke this method and examine myUrl, it will be host/pathname?freeToPlay=. In my opinion, this is incorrect - I would have expected to have received host/pathname back (as the value of freeToPlay is undefined). The current behaviour would make sense if I explicitly passed null to the url.format method, but I did not.
Hope i've explained this well enough.
The text was updated successfully, but these errors were encountered:
punmechanic
changed the title
url.format includes undefined parameters in querystring
url.format/querystring.stringify include undefined parameters in querystring
Apr 18, 2015
url.format
(on node 0.12.0, which in turn callsquerystring.stringify
) will include parameters on an object that are explicitly undefined. If you don't want to read the real life consequences, here's some example code demonstrating the issue - just skip to the bottom.Using an excerpt from the library I am developing:
If I do not pass in
freeToPlayOnly
toall()
, then obviously it will beundefined
. The object passed toriot.get
will, therefore, be{ freeToPlay: undefined }
. Insideriot.get
, the following code is invoked:As you can see from the above code, our
{ freeToPlay: undefined }
is passed to theget
function asqueryParameters
, which are then passed toquery
.If you invoke this method and examine
myUrl
, it will behost/pathname?freeToPlay=
. In my opinion, this is incorrect - I would have expected to have receivedhost/pathname
back (as the value offreeToPlay
is undefined). The current behaviour would make sense if I explicitly passednull
to theurl.format
method, but I did not.Hope i've explained this well enough.
The text was updated successfully, but these errors were encountered: