Skip to content

Commit

Permalink
Fix dynamic parameter regex replacement in processComplexMatch
Browse files Browse the repository at this point in the history
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
  • Loading branch information
erikjuhani committed Sep 21, 2024
1 parent e3b4d2f commit 4280f48
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/generate-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function processComplexMatch (thing, keys) {
// (i.e. /:id, /:name, etc...) with the name(s) of those parameter(s)
// This could have been accomplished with replaceAll for Node version 15 and above
// no-useless-escape is disabled since we need three backslashes
.replace(/\(\?\:\(\[\^\\\/\]\+\?\)\)/g, () => `{${keys[i++].name}}`) // eslint-disable-line no-useless-escape
.replace(/(?:\\\/)?\(\?\:(?:\\\/)?\(\[\^(?:\\)?\/\]\+\?\)\)\\\//, () => `/{${keys[i++].name}}/`) // eslint-disable-line no-useless-escape
.replace(/\\(.)/g, '$1')
// The replace below removes the regex used at the start of the string and
// the regex used to match the query parameters
Expand Down

0 comments on commit 4280f48

Please sign in to comment.