Skip to content

Commit 4280f48

Browse files
committed
Fix dynamic parameter regex replacement in processComplexMatch
The replace failed to inject the route parameter as the layer regex was changed from `/^\/(?:([^\/]+?))\/?(?=\/|$)/i` to `/^(?:\/([^/]+?))\/?(?=\/|$)/i`. Now both regex cases are taken into consideration. The regex was changed to use optional non-capturing groups for the differences between the two possible regex patterns. Link to playground using the new regex format: https://regex101.com/r/cursDu/1
1 parent e3b4d2f commit 4280f48

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/generate-doc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function processComplexMatch (thing, keys) {
102102
// (i.e. /:id, /:name, etc...) with the name(s) of those parameter(s)
103103
// This could have been accomplished with replaceAll for Node version 15 and above
104104
// no-useless-escape is disabled since we need three backslashes
105-
.replace(/\(\?\:\(\[\^\\\/\]\+\?\)\)/g, () => `{${keys[i++].name}}`) // eslint-disable-line no-useless-escape
105+
.replace(/(?:\\\/)?\(\?\:(?:\\\/)?\(\[\^(?:\\)?\/\]\+\?\)\)\\\//, () => `/{${keys[i++].name}}/`) // eslint-disable-line no-useless-escape
106106
.replace(/\\(.)/g, '$1')
107107
// The replace below removes the regex used at the start of the string and
108108
// the regex used to match the query parameters

0 commit comments

Comments
 (0)