diff --git a/src/adapter/web-standard/index.ts b/src/adapter/web-standard/index.ts index c8effd95..383f74dc 100644 --- a/src/adapter/web-standard/index.ts +++ b/src/adapter/web-standard/index.ts @@ -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` + diff --git a/src/dynamic-handle.ts b/src/dynamic-handle.ts index a7d96d17..f7dbbab1 100644 --- a/src/dynamic-handle.ts +++ b/src/dynamic-handle.ts @@ -29,7 +29,7 @@ export const createDynamicHandler = (app: AnyElysia) => { const { mapResponse, mapEarlyResponse } = app['~adapter'].handler return async (request: Request): Promise => { - 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) diff --git a/test/core/elysia.test.ts b/test/core/elysia.test.ts index ea13d0fc..5c4c1152 100644 --- a/test/core/elysia.test.ts +++ b/test/core/elysia.test.ts @@ -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); + }) + }) })