Skip to content

Commit a360f07

Browse files
committed
fix: handle paths with spaces (#944)
1 parent 94c63cc commit a360f07

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/adapter/web-standard/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const WebStandardAdapter: ElysiaAdapter = {
7979
const hasTrace = app.event.trace.length > 0
8080

8181
fnLiteral +=
82-
`const u=r.url,` +
82+
`const u=decodeURI(r.url),` +
8383
`s=u.indexOf('/',${standardHostname ? 11 : 7}),` +
8484
`qi=u.indexOf('?', s + 1)\n` +
8585
`let p\n` +

src/dynamic-handle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const createDynamicHandler = (app: AnyElysia) => {
2929
const { mapResponse, mapEarlyResponse } = app['~adapter'].handler
3030

3131
return async (request: Request): Promise<Response> => {
32-
const url = request.url,
32+
const url = decodeURI(request.url),
3333
s = url.indexOf('/', 11),
3434
qi = url.indexOf('?', s + 1),
3535
path = qi === -1 ? url.substring(s) : url.substring(s, qi)

test/core/elysia.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,26 @@ describe('Edge Case', () => {
173173
// @ts-expect-error private property
174174
expect(main.getGlobalRoutes().length).toBe(2)
175175
})
176+
177+
describe('handle path with spaces', () => {
178+
it('when AOT is on', async () => {
179+
const PATH = "/y a y";
180+
181+
const app = new Elysia().get(PATH, () => "result from a path wirh spaces");
182+
183+
const response = await app.handle(new Request(`http://localhost${PATH}`));
184+
185+
expect(response.status).toBe(200);
186+
})
187+
188+
it('when AOT is off', async () => {
189+
const PATH = "/y a y";
190+
191+
const app = new Elysia({ aot: false }).get(PATH, () => "result from a path wirh spaces");
192+
193+
const response = await app.handle(new Request(`http://localhost${PATH}`));
194+
195+
expect(response.status).toBe(200);
196+
})
197+
})
176198
})

0 commit comments

Comments
 (0)