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

Params do not encode %20 to + or space #924

Open
anton89 opened this issue Nov 25, 2024 · 3 comments · May be fixed by #958
Open

Params do not encode %20 to + or space #924

anton89 opened this issue Nov 25, 2024 · 3 comments · May be fixed by #958
Labels
bug Something isn't working

Comments

@anton89
Copy link

anton89 commented Nov 25, 2024

What version of Elysia is running?

1.1.25

What platform is your computer?

wsl

What steps can reproduce the bug?


import Elysia, { t } from "elysia";

const api = new Elysia().get("/:id", ({ params }) => params, {
  params: t.Object({
    id: t.String(),
  }),
});


const url = new URL("http://localhost:3000/hello world");
console.log(url.href);

const result = await api
  .handle(new Request(url.href))
  .then((response) => response.json() );
console.log("🚀 ~ result:", result)
//🚀 ~ result: { id: 'hello%20world' }

What is the expected behavior?

The id in params should be hello world

What do you see instead?

hello%20world

Additional information

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@anton89 anton89 added the bug Something isn't working label Nov 25, 2024
@fredericoo
Copy link

i’d say behaving as expected — url parameters shouldn’t have special characters, otherwise it could behave erratically with routing (e.g.: /hello%2Fworld, would id be hello/world? Then if i go to /hello/world how will it know to escape the slash or not?)

to put it simply, the encoding of URI components in the pathname happens on the requester’s end (postman, insomnia, the browser) and elysia just takes it as it comes without decoding.

@anton89
Copy link
Author

anton89 commented Dec 3, 2024

i’d say behaving as expected — url parameters shouldn’t have special characters, otherwise it could behave erratically with routing (e.g.: /hello%2Fworld, would id be hello/world? Then if i go to /hello/world how will it know to escape the slash or not?)

to put it simply, the encoding of URI components in the pathname happens on the requester’s end (postman, insomnia, the browser) and elysia just takes it as it comes without decoding.

but it already parsed and go through root endpoint ** shouldn't it just automatically encode it, if the id hello/world then it should go to hello first and then tried to encode world

this is the default behavior for queryString too btw

@macabeus
Copy link
Contributor

The PR #958 also fixes this issue

@macabeus macabeus linked a pull request Dec 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants