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

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" } ] }

  1. Navigate in your browser to the function url. It should show an empty JSON object on screen.
  2. Add '?test1=success' to the query string in the browser. It should show the following object: {"test1":"success"}.
  3. Add &test2 to the query string in the browser. It should show an object that includes the test1, and `test2' keys. It actually does not include test2.
  4. Add &test3= to the query string in the browser. It should show an object that includes the test1, test2, and test3 keys. It actually does not include test2 or test3.

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;

Provide any related information