Skip to content

Commit 8bd0e36

Browse files
dinwwwhclaude
andauthored
test(router): pin a catch-all tail segment ending in } as literal (#193)
<!-- claude-projects-attribution: {"github_login":"dinwwwh"} --> _Requested by **dinwwwh** · [project thread](https://claude.ai/code/project/chan_01UcKMz91tMarPV1kWLVgLYE?thread=cmsg_01UcKMz91tMarPV1kWLVgLYE6swgSUM9SyULmBVdRjY2t7)_ ## What This is a test-only change. The literal-text test in `router.test.ts` now adds `/f/{+p}/id}` and checks two requests: - `/f/1/id}` matches it, with `{ p: '1' }`. - `/f/1/id` matches nothing. ## Why Since #186, the tree build calls `toSegment` only for parts that start with `{`. A catch-all's tail segments still go through `toSegment` whatever they start with, and so do `parse`'s callers (`createPrefixMatcher` and the two-catch-all check in `add`). Mutation testing found that dropping the leading-`{` half of `toSegment`'s param check failed no test, even with the 73 tests now on main. With that mutant, `id}` becomes a param named `d`, so `/f/1/id` matches. The new assertions catch it. ## Checks - All 73 router tests pass, and `pnpm check` passes. - With that mutant applied, the test fails. --- _Generated by [Claude Code](https://claude.ai/code/session_01VVaw7Sutbw6xMTMyDFeNfw)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1e46b22 commit 8bd0e36

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎packages/router/tests/router.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe('Router', () => {
9696
'/{id',
9797
'/id}',
9898
'/id}/{x}',
99+
'/f/{+p}/id}',
99100
)
100101

101102
for (const path of [
@@ -117,6 +118,8 @@ describe('Router', () => {
117118
expect(router.match('GET', '/anything')).toBeUndefined()
118119
expect(router.match('GET', '/x')).toBeUndefined()
119120
expect(router.match('GET', '/itemsfoo')).toBeUndefined()
121+
expect(router.match('GET', '/f/1/id}')).toEqual({ data: '/f/{+p}/id}', params: { p: '1' } })
122+
expect(router.match('GET', '/f/1/id')).toBeUndefined()
120123

121124
// only a whole-segment `{name}` is a param
122125
expect(router.match('GET', '/a/%7Bid%7D.json')).toEqual({

0 commit comments

Comments
 (0)