Skip to content

Commit

Permalink
fix: handle paths with spaces (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
macabeus committed Dec 23, 2024
1 parent 94c63cc commit a360f07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/adapter/web-standard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const WebStandardAdapter: ElysiaAdapter = {
const hasTrace = app.event.trace.length > 0

fnLiteral +=
`const u=r.url,` +
`const u=decodeURI(r.url),` +
`s=u.indexOf('/',${standardHostname ? 11 : 7}),` +
`qi=u.indexOf('?', s + 1)\n` +
`let p\n` +
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createDynamicHandler = (app: AnyElysia) => {
const { mapResponse, mapEarlyResponse } = app['~adapter'].handler

return async (request: Request): Promise<Response> => {
const url = request.url,
const url = decodeURI(request.url),
s = url.indexOf('/', 11),
qi = url.indexOf('?', s + 1),
path = qi === -1 ? url.substring(s) : url.substring(s, qi)
Expand Down
22 changes: 22 additions & 0 deletions test/core/elysia.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,26 @@ describe('Edge Case', () => {
// @ts-expect-error private property
expect(main.getGlobalRoutes().length).toBe(2)
})

describe('handle path with spaces', () => {
it('when AOT is on', async () => {
const PATH = "/y a y";

const app = new Elysia().get(PATH, () => "result from a path wirh spaces");

const response = await app.handle(new Request(`http://localhost${PATH}`));

expect(response.status).toBe(200);
})

it('when AOT is off', async () => {
const PATH = "/y a y";

const app = new Elysia({ aot: false }).get(PATH, () => "result from a path wirh spaces");

const response = await app.handle(new Request(`http://localhost${PATH}`));

expect(response.status).toBe(200);
})
})
})

0 comments on commit a360f07

Please sign in to comment.