Support route parameter regex in controller route function

This commit is contained in:
Alice Gaudon 2020-06-14 21:48:19 +02:00
parent fa42b8991b
commit fa3e5bdb19

View File

@ -15,7 +15,7 @@ export default abstract class Controller {
path = path.replace(/:[a-zA-Z_-]+\??/g, '' + params); path = path.replace(/:[a-zA-Z_-]+\??/g, '' + params);
} else if (Array.isArray(params)) { } else if (Array.isArray(params)) {
let i = 0; let i = 0;
for (const match of path.matchAll(/:[a-zA-Z_-]+\??/g)) { for (const match of path.matchAll(/:[a-zA-Z_-]+(\(.*\))?\??/g)) {
if (match.length > 0) { if (match.length > 0) {
path = path.replace(match[0], typeof params[i] !== 'undefined' ? params[i] : ''); path = path.replace(match[0], typeof params[i] !== 'undefined' ? params[i] : '');
} }