diff --git a/core/base-service/route.js b/core/base-service/route.js index 7c497fc872eac..8c2e2053aa270 100644 --- a/core/base-service/route.js +++ b/core/base-service/route.js @@ -33,13 +33,19 @@ function prepareRoute({ base, pattern, format, capture, withPng }) { regex = new RegExp(`^${makeFullUrl(base, format)}(${extensionRegex})$`) captureNames = capture || [] } else { - const fullPattern = `${makeFullUrl(base, pattern)}:ext(${extensionRegex})` + const fullPatternWithoutExt = `${makeFullUrl(base, pattern)}` const keys = [] - regex = pathToRegexp(fullPattern, keys, { - strict: true, + const pathRegex = pathToRegexp(fullPatternWithoutExt, keys, { + trailing: false, sensitive: true, }) - captureNames = keys.map(item => item.name).slice(0, -1) + const sourceWithoutEnd = pathRegex.regexp.source.replace(/\$$/, '') + // workaround for path-to-regexp not supporting regex anymore + regex = new RegExp( + `${sourceWithoutEnd}(${extensionRegex})$`, + pathRegex.regexp.flags, + ) + captureNames = keys.map(item => item.name) } return { regex, captureNames } } diff --git a/package-lock.json b/package-lock.json index 41e7c3dd5982e..a191443a63e6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "mvncmp": "^1.0.0", "node-pg-migrate": "^8.0.4", "parse-link-header": "^2.0.0", - "path-to-regexp": "^6.3.0", + "path-to-regexp": "^8.4.2", "pg": "^8.20.0", "priorityqueuejs": "^2.0.0", "prom-client": "^15.1.3", @@ -25279,9 +25279,14 @@ } }, "node_modules/path-to-regexp": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", - "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==" + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } }, "node_modules/path-type": { "version": "4.0.0", diff --git a/package.json b/package.json index a020184bd4169..aad287c0d778a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mvncmp": "^1.0.0", "node-pg-migrate": "^8.0.4", "parse-link-header": "^2.0.0", - "path-to-regexp": "^6.3.0", + "path-to-regexp": "^8.4.2", "pg": "^8.20.0", "priorityqueuejs": "^2.0.0", "prom-client": "^15.1.3",