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 21, 2024
1 parent 9ab72e8 commit 94bf163
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,7 @@ export const composeGeneralHandler = (

if (app.event.request.length) fnLiteral += `let re`

fnLiteral += `\nconst url = request.url
fnLiteral += `\nconst url = decodeURI(request.url)
const s = url.indexOf('/', ${standardHostname ? 11 : 7})
const qi = url.indexOf('?', s + 1)
let path
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type DynamicHandler = {
export const createDynamicHandler =
(app: Elysia<any, any, any, any, any, any, any, any>) =>
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 94bf163

Please sign in to comment.