Skip to content
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

Dynamic route param values ignored for non-alpha(string) types #284

Closed
jwhazel opened this issue Jul 31, 2024 · 1 comment
Closed

Dynamic route param values ignored for non-alpha(string) types #284

jwhazel opened this issue Jul 31, 2024 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@jwhazel
Copy link

jwhazel commented Jul 31, 2024

Repro steps

Create a function with dynamic route parameters that either have no constraints, or accept constraints other than alpha. The v4 example here will suffice: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2&pivots=programming-language-javascript#customize-the-http-endpoint

const { app } = require('@azure/functions');

app.http('httpTrigger1', {
    methods: ['GET'],
    authLevel: 'anonymous',
    route: 'products/{category:alpha}/{id:int?}',
    handler: async (request, context) => {
        const category = request.params.category;
        const id = request.params.id;

        return { body: `Category: ${category}, ID: ${id}` };
    },
});

Expected behavior

Given a route of products/abc/123, I expect the output to be Category: abc, ID: 123

Actual behavior

The actual output is Category: abc, ID: undefined

Related information

  • It seems there's some sort of type checking going on behind the scenes and any value that is either a Number, Null, or Boolean in javascript doesn't get captured. E.g. products/abc/null or products/abc/true also return undefined. You can dump request.params and see that the keys simply don't exist.
  • The existence of a constraint or optional qualifier ? doesn't seem to make a difference. I only included it above because that's a verbatim example from the documentation.
  • I'm running version 4.0.5198 locally. I can confirm the same issue occurs in a production Azure environment with Node 20. I have not had the chance to test other versions of Core Tools or Node.
@ejizba
Copy link
Contributor

ejizba commented Jul 31, 2024

Hi @jwhazel thanks for reporting - I'm going to close as duplicate of #285 (it was in a different repo, but I just transferred it to this repo). Please see this comment for the recommended workaround: #285 (comment)

@ejizba ejizba closed this as completed Jul 31, 2024
@ejizba ejizba added the duplicate This issue or pull request already exists label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants