From 4280f48608d5bf8505c032e7e0b421f9973cd9d5 Mon Sep 17 00:00:00 2001 From: Erik Kinnunen Date: Sat, 21 Sep 2024 22:39:11 +0300 Subject: [PATCH] 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 --- lib/generate-doc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generate-doc.js b/lib/generate-doc.js index 803f132..59c7c5c 100644 --- a/lib/generate-doc.js +++ b/lib/generate-doc.js @@ -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