Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(routing): add type check for non-string paths in lookup
  • Loading branch information
marshallswain committed Dec 19, 2025
commit a8d36191e0aa88f859c04e70dc1cd16b860945ee
10 changes: 10 additions & 0 deletions packages/routing/src/base-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ describe('BaseRouter', () => {
assert.ok(result2)
assert.deepStrictEqual(result2.params['path'], ['a', 'b', 'c'])
})

it('returns null for non-string paths', () => {
const router = new TestRouter()
router.insert('/users', 'users-handler')

assert.strictEqual(router.lookup(null as any), null)
assert.strictEqual(router.lookup(undefined as any), null)
assert.strictEqual(router.lookup(123 as any), null)
assert.strictEqual(router.lookup({} as any), null)
})
})
4 changes: 4 additions & 0 deletions packages/routing/src/base-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export abstract class BaseRouter<T = any> implements RouterInterface<T> {
}

lookup(path: string): LookupResult<T> | null {
if (typeof path !== 'string') {
return null
}

const normalizedPath = normalizePath(path)

for (const route of this.routes) {
Expand Down
Loading