Skip to content

Middleware matchers generate invalid Golang regexp capture groups #1794

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
ascorbic opened this issue Nov 21, 2022 · 1 comment · Fixed by #1809
Closed

Middleware matchers generate invalid Golang regexp capture groups #1794

ascorbic opened this issue Nov 21, 2022 · 1 comment · Fixed by #1809
Assignees
Labels
priority: medium type: bug code to address defects in shipped code

Comments

@ascorbic
Copy link
Contributor

ascorbic commented Nov 21, 2022

We currently generate edge functions manifests with patterns generated from the middleware-manifest matcher regexp. The problem is that this now uses named capture groups, which have a different syntax in golang than JS.

In JS, a named capture group has the form (?<id> ... but Golang needs the equivalent to be (?P<id> .... Right now when converting the JS pattern into Golang we just strip lookeaheads. It seems we may also need to convert these named capture groups too.

This is caught by the e2e test edge-render-getserversideprops, which gives a 500 error for /123 as the edge function does not match, causing it to try to use a lambda, which has invalid syntax

The code is in here: https://github.com/netlify/next-runtime/blob/main/packages/runtime/src/helpers/matchers.ts

@ascorbic ascorbic added the type: bug code to address defects in shipped code label Nov 21, 2022
@MarcL MarcL assigned MarcL and orinokai and unassigned MarcL Nov 22, 2022
@orinokai
Copy link
Contributor

@ascorbic i attempted this by doing a simple string replace at the same point we strip lookaheads and i have a draft PR here: #1809

However, it doesn't currently work because the edge-bundler tries to compile the pattern into a Regex object and thus gives an error: https://github.com/netlify/edge-bundler/blob/main/node/manifest.ts#L79

It doesn't seem necessary for the edge-bundler to compile these regex patterns, so I created an edge-bundler PR to simply use the patterns as strings: netlify/edge-bundler#226

However, when doing so I realised that we might want to persue an alternative route, which would be to do the syntax transformation in the edge-bundler itself? Would be interested in your thoughts on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants