From 018c8b67e5d45c196f12574bbe764616d0dbc5e7 Mon Sep 17 00:00:00 2001 From: ilsyaa Date: Tue, 18 Nov 2025 19:43:26 +0700 Subject: [PATCH 1/2] feat: add wildcard support for route matching --- src/request.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/request.ts b/src/request.ts index 3e89801..d53687b 100644 --- a/src/request.ts +++ b/src/request.ts @@ -725,6 +725,12 @@ export class Request extends Macroable { return false } + if (identifier.includes('*')) { + const escaped = identifier.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&') + const regex = new RegExp('^' + escaped.replace(/\*/g, '.*') + '$') + return regex.test(route.name || route.pattern) + } + return route.handler.reference === identifier } ) From 2970af847ff45e633b595676590428f1cb4784ae Mon Sep 17 00:00:00 2001 From: ilsyaa Date: Wed, 19 Nov 2025 14:09:02 +0700 Subject: [PATCH 2/2] test: Add unit tests for matchesRoute wildcard logic --- tests/request.spec.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/request.spec.ts b/tests/request.spec.ts index eb27ea5..b8e451e 100644 --- a/tests/request.spec.ts +++ b/tests/request.spec.ts @@ -944,6 +944,36 @@ test.group('Request', () => { }) }) + test('find if an wildcard identifiers matches the request route name', async ({ assert }) => { + const { url } = await httpServer.create((req, res) => { + const request = new RequestFactory().merge({ req, res, encryption }).create() + request.ctx = new HttpContextFactory().merge({ request }).create() + ;(request.ctx.route as any) = { + pattern: '/users/:id', + name: 'admin.users.show', + handler: { name: '#controllers/user', handle: () => {} }, + } + + res.writeHead(200, { 'content-type': 'application/json' }) + res.end( + JSON.stringify({ + wildcard_trailing_match: request.matchesRoute(['admin.users.*']), + wildcard_middle_match: request.matchesRoute(['admin.*.show']), + wildcard_array_match: request.matchesRoute(['admin.posts.*', 'admin.users.*']), + wildcard_no_match: request.matchesRoute(['admin.invoices.*']), + }) + ) + }) + + const { body } = await supertest(url).get('/users/1') + assert.deepEqual(body, { + wildcard_trailing_match: true, + wildcard_middle_match: true, + wildcard_array_match: true, + wildcard_no_match: false, + }) + }) + test('get request json representation', async ({ assert }) => { const { url } = await httpServer.create((req, res) => { const request = new RequestFactory().merge({ req, res, encryption }).create()