Empty Query Parameters not coming through · Issue #253 · Azure/azure-functions-nodejs-worker (original) (raw)
Empty Query parameters are not correctly parsed into the req.query object.
Investigative information
- Timestamp: 1573138139970
- Function App name: N/A Repro Below
- Function name(s) (as appropriate): N/A Repro Below
- Invocation ID: N/A Repro Below
- Region: US Central
Repro steps
Provide the steps required to reproduce the problem:
Run the following extremely useful query to JSON function:
index.js:
module.exports = async function (context, req) { return { status: 200, body: {...req.query}, headers: { 'content-type': 'application/json', }, }; }
function.json:
{ "bindings": [ { "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get" ] }, { "type": "http", "direction": "out", "name": "$return" } ] }
- Navigate in your browser to the function url. It should show an empty JSON object on screen.
- Add '?test1=success' to the query string in the browser. It should show the following object:
{"test1":"success"}
. - Add
&test2
to the query string in the browser. It should show an object that includes thetest1
, and `test2' keys. It actually does not include test2. - Add
&test3=
to the query string in the browser. It should show an object that includes thetest1
,test2
, andtest3
keys. It actually does not includetest2
ortest3
.
Expected behavior
I expect the query parsing behavior to match the queryParams behavior of the built in URL object - each key in the query shows up in the output, defaulting to an empty string.
Actual behavior
The query object only includes keys that have values other than the empty string.
Known workarounds
Currently I have to do the following:
const url = new URL(req.url); const correctQuery = url.queryParams;
Related information
Provide any related information
- Programming language used: Javascript