Skip to content

Commit 15790aa

Browse files
orinokaiascorbic
andauthored
fix: transform Regex named capture groups for Golang (#1809)
* fix: transform named capture groups for Golang * chore: enable failing edge-render-getserversideprops test * fix: transform named capture groups to simple capture groups Co-authored-by: Matt Kane <[email protected]> * chore: remove unnecessary escape for linter * chore: fix prettier style complaint Co-authored-by: Matt Kane <[email protected]>
1 parent 3682002 commit 15790aa

File tree

6 files changed

+5
-2
lines changed

6 files changed

+5
-2
lines changed

packages/runtime/src/helpers/edge.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { RouteHas } from 'next/dist/lib/load-custom-routes'
1111
import { outdent } from 'outdent'
1212

1313
import { getRequiredServerFiles, NextConfig } from './config'
14-
import { makeLocaleOptional, stripLookahead } from './matchers'
14+
import { makeLocaleOptional, stripLookahead, transformCaptureGroups } from './matchers'
1515
import { RoutesManifest } from './types'
1616

1717
// This is the format as of [email protected]
@@ -267,7 +267,7 @@ const writeEdgeFunction = async ({
267267

268268
// We add a defintion for each matching path
269269
return matchers.map((matcher) => {
270-
const pattern = stripLookahead(matcher.regexp)
270+
const pattern = transformCaptureGroups(stripLookahead(matcher.regexp))
271271
return { function: name, pattern, name: edgeFunctionDefinition.name, cache }
272272
})
273273
}

packages/runtime/src/helpers/matchers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export const stripLookahead = (regex: string) => {
2424
}
2525
}
2626

27+
// The Go regexp lib has alternative syntax for named capture groups
28+
export const transformCaptureGroups = (regex: string) => regex.replace(/\(\?<\w+>/, '(')
29+
2730
const LOCALIZED_REGEX_PREFIX = '(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/([^/.]{1,}))'
2831
const OPTIONAL_REGEX_PREFIX = '(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/([^/.]{1,}))?'
2932

0 commit comments

Comments
 (0)