Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special characters in request params #184

Open
wants to merge 1 commit into
base: v4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/Router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ describe('Router', () => {
router.get('/foo', vi.fn()).get('/foo', vi.fn())
}).not.toThrow()
})

it('allows special characters in params', async () => {
const specialRouter = Router()
specialRouter.get('/foo/:id', (request) => new Response(`id: ${request.params.id}`))

const response = await specialRouter.handle(buildRequest({ path: '/foo/user%3A1234' }))

expect(await response.text()).toBe('id: user:1234')
})
})

describe(`.handle({ method = 'GET', url }, ...args)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const Router = <
}),
routes,
async handle (request: RequestLike, ...args) {
let response, match, url = new URL(request.url), query: any = request.query = { __proto__: null }
let response, match, url = new URL(decodeURIComponent(request.url)), query: any = request.query = { __proto__: null }
for (let [k, v] of url.searchParams) {
query[k] = query[k] === undefined ? v : [query[k], v].flat()
}
Expand Down