Skip to content

Commit

Permalink
fix(router/trie-router): fix label with trailing wildcard pattern (#3892
Browse files Browse the repository at this point in the history
)
  • Loading branch information
usualoma authored Feb 6, 2025
1 parent 066c342 commit 6b6fbad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/router/common.case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ export const runTest = ({
})
})

describe('Capture regex pattern has trailing wildcard', () => {
beforeEach(() => {
router.add('GET', '/:dir{[a-z]+}/*/file.html', 'file.html')
})

it('GET /foo/bar/file.html', () => {
const res = match('GET', '/foo/bar/file.html')
expect(res.length).toBe(1)
expect(res[0].handler).toEqual('file.html')
expect(res[0].params['dir']).toEqual('foo')
})
})

describe('non ascii characters', () => {
beforeEach(() => {
router.add('ALL', '/$/*', 'middleware $')
Expand Down
5 changes: 4 additions & 1 deletion src/router/linear-router/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ describe('LinearRouter', () => {
skip: [
{
reason: 'UnsupportedPath',
tests: ['Multi match > `params` per a handler > GET /entry/123/show'],
tests: [
'Multi match > `params` per a handler > GET /entry/123/show',
'Capture regex pattern has trailing wildcard > GET /foo/bar/file.html',
],
},
{
reason: 'LinearRouter allows trailing slashes',
Expand Down
1 change: 1 addition & 0 deletions src/router/trie-router/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class Node<T> {
const astNode = node.#children['*']
if (astNode) {
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params))
astNode.#params = params
tempNodes.push(astNode)
}
continue
Expand Down

0 comments on commit 6b6fbad

Please sign in to comment.