Skip to content

Empty Query Parameters not coming through #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Crisfole opened this issue Nov 7, 2019 · 2 comments
Closed

Empty Query Parameters not coming through #253

Crisfole opened this issue Nov 7, 2019 · 2 comments
Assignees

Comments

@Crisfole
Copy link

Crisfole commented Nov 7, 2019

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

Related information

Provide any related information

  • Programming language used: Javascript
@mhoeger
Copy link
Contributor

mhoeger commented Nov 14, 2019

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 :)

@mhoeger mhoeger self-assigned this Nov 14, 2019
@mhoeger mhoeger added this to the Triaged milestone Nov 14, 2019
@mhoeger
Copy link
Contributor

mhoeger commented Feb 22, 2021

Resolved with #326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants