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: handle paths with spaces (#944) #958

Open
wants to merge 1 commit into
base: main
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
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 @@ -38,7 +38,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 @@ -206,4 +206,26 @@ describe('Edge Case', () => {
expect(response).toBe('params-transform');
})
})

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);
})
})
})
Loading