Skip to content

Commit fa90feb

Browse files
committed
update prepareRoute to inject extention regex outside of pathToRegexp context
due to breaking changes in pathToRegexp that removed regex support
1 parent b82c7b5 commit fa90feb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

core/base-service/route.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ function prepareRoute({ base, pattern, format, capture, withPng }) {
3333
regex = new RegExp(`^${makeFullUrl(base, format)}(${extensionRegex})$`)
3434
captureNames = capture || []
3535
} else {
36-
const fullPattern = `${makeFullUrl(base, pattern)}:ext(${extensionRegex})`
36+
const fullPatternWithoutExt = `${makeFullUrl(base, pattern)}`
3737
const keys = []
38-
regex = pathToRegexp(fullPattern, keys, {
38+
const pathRegex = pathToRegexp(fullPatternWithoutExt, keys, {
3939
trailing: false,
4040
sensitive: true,
4141
})
42-
captureNames = keys.map(item => item.name).slice(0, -1)
42+
const sourceWithoutEnd = pathRegex.regexp.source.replace(/\$$/, '')
43+
// workaround for path-to-regexp not supporting regex anymore
44+
regex = new RegExp(
45+
`${sourceWithoutEnd}(${extensionRegex})$`,
46+
pathRegex.regexp.flags,
47+
)
48+
captureNames = keys.map(item => item.name)
4349
}
4450
return { regex, captureNames }
4551
}

0 commit comments

Comments
 (0)