Filename-based function routing not working as expected

As per the routing documentation under https://developers.cloudflare.com/pages/platform/functions/routing/, adding brackets or double-brackets to file names will generate a routing configuration which will route URLs with additional path segments to the function in question:

/functions/foo/[[bar]].js // example.com/foo/1/2/3 will route to this function

This works great unless file names contain hyphens:

/functions/foo-bar/[[foo-bar]].js // example.com/foo-bar/1/2/3 is supposed to route to this function

This will result in an exception with the error message Unexpected MODIFIER at 23, expected END. The request seems to never reach the function’s onRequest.

If it’s at all relevant, this was tested on a pages project running on a custom subdomain using a preview build. I haven’t tested this on my stable environment, so this might be a contributing factor?

Anyways, easy to work around this, but it looks like a bug in how routing for functions is handled.

I think whatever you use as the [[placeholder]] needs to be a legal Javascript identifier, because you access its contents like context.params.bar, and context.params.foo-bar won’t work.