Empty Query Parameters not coming through
Crisfole opened this issue · 2 comments
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
&test2to 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, andtest3keys. It actually does not includetest2ortest3.
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
Hi @Crisfole, the reason why we don't pass this information is because of a serializing issue that we discovered with using proto3.
Here's the original issue: #142
And this is the fix needed: Azure/azure-functions-language-worker-protobuf#21
While this is unavailable, our recommended workaround is to access query param data through context.bindingData.query, where the same information is available)
module.exports = async function (context, req) {
return {
status: 200,
body: {...context.bindingData.query},
headers: {
'content-type': 'application/json',
},
};
}
Now that I type this out, I'm realizing that we can actually map that data over so it's available through req. Using this issue to track that work :)