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

Get encoded path params #3872

Open
kawmra opened this issue Jan 31, 2025 · 0 comments
Open

Get encoded path params #3872

kawmra opened this issue Jan 31, 2025 · 0 comments
Labels
enhancement New feature or request.

Comments

@kawmra
Copy link

kawmra commented Jan 31, 2025

What is the feature you are proposing?

Currently, with the following route, there is no way to differentiate between accessing /kv/foo/bar and /kv/foo%2Fbar:

app.get("/kv/:key{.+}", async (c) => {
  console.log(c.req.param("key")) // => Always returns "foo/bar" in both cases
})

It seems that since #659, c.req.param() now returns a decoded string by default.
But I want to distinguish whether the input parameter contained a literal / or if it was an encoded %2F.

I know that c.req.path can be used to get the raw path, but manually parsing it is cumbersome.
And if the route hierarchy (/kv) changes, the position of :key would shift, and there's no type checking to detect such changes, which is concerning.

A method like c.req.rawParam() would be useful I think.

@kawmra kawmra added the enhancement New feature or request. label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant