Skip to content

Commit

Permalink
Merge branch 'canary' into fix/cf-streaming-write
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Feb 28, 2022
2 parents e66f2b1 + 7ca78dd commit 876763c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/next/shared/lib/router/utils/route-regex.ts
@@ -1,15 +1,11 @@
import { escapeStringRegexp } from '../../escape-regexp'

interface Group {
pos: number
repeat: boolean
optional: boolean
}

// this isn't importing the escape-string-regex module
// to reduce bytes
function escapeRegex(str: string) {
return str.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
}

function parseParameter(param: string) {
const optional = param.startsWith('[') && param.endsWith(']')
if (optional) {
Expand All @@ -34,7 +30,7 @@ export function getParametrizedRoute(route: string) {
groups[key] = { pos: groupIndex++, repeat, optional }
return repeat ? (optional ? '(?:/(.+?))?' : '/(.+?)') : '/([^/]+?)'
} else {
return `/${escapeRegex(segment)}`
return `/${escapeStringRegexp(segment)}`
}
})
.join('')
Expand Down Expand Up @@ -92,7 +88,7 @@ export function getParametrizedRoute(route: string) {
: `/(?<${cleanedKey}>.+?)`
: `/(?<${cleanedKey}>[^/]+?)`
} else {
return `/${escapeRegex(segment)}`
return `/${escapeStringRegexp(segment)}`
}
})
.join('')
Expand Down

0 comments on commit 876763c

Please sign in to comment.