You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What runtime/platform is your app running on? (with version if possible)
Node.js
What steps can reproduce the bug?
Description
When making a request using the Hono client to a route with a path parameter, parameter values are not percent-encoded, resulting in incorrect URLs being requested if any of the path parameter values contain certain characters.
Run the server by executing the command npm run dev
Run the client by executing the command npx tsx src/client.ts
What is the expected behavior?
The client should call the /:x route on the server, passing the string value "test/value" as the :x path parameter. It would do this by percent-encoding all of the path parameters before adding them to the URL, resulting in a request being made to the path /test%2Fvalue.
This should result in the response {"x": "test/value"} being received and logged on the client.
What do you see instead?
The client instead makes a request to /test/value, which does not resolve to the /:x route and thus results in a 404 error.
Additional information
As a workaround, you can call encodeURIComponent on path parameter values, and the parameter values are automatically decoded on the server.
I think that doing this automatically in Hono would solve the issue, though this would break user code that already does this. Perhaps the param option can be deprecated and a new option params or pathParams can be introduced that automatically percent-encodes its values.
The text was updated successfully, but these errors were encountered:
If you want to handle /test/value, you should write the following:
constapp=newHono().get('/:x{.+}',(c)=>{//...})
Second, the Hono Client adds the just path string with param. So it should not encode the value of param. The following works correctly. There is no problem.
What version of Hono are you using?
4.7.1
What runtime/platform is your app running on? (with version if possible)
Node.js
What steps can reproduce the bug?
Description
When making a request using the Hono client to a route with a path parameter, parameter values are not percent-encoded, resulting in incorrect URLs being requested if any of the path parameter values contain certain characters.
Steps to reproduce
Create a new Hono project.
Add the following Hono server implementation.
index.ts
client.ts
Run the server by executing the command
npm run dev
Run the client by executing the command
npx tsx src/client.ts
What is the expected behavior?
The client should call the
/:x
route on the server, passing the string value"test/value"
as the:x
path parameter. It would do this by percent-encoding all of the path parameters before adding them to the URL, resulting in a request being made to the path/test%2Fvalue
.This should result in the response
{"x": "test/value"}
being received and logged on the client.What do you see instead?
The client instead makes a request to
/test/value
, which does not resolve to the/:x
route and thus results in a 404 error.Additional information
As a workaround, you can call
encodeURIComponent
on path parameter values, and the parameter values are automatically decoded on the server.I think that doing this automatically in Hono would solve the issue, though this would break user code that already does this. Perhaps the
param
option can be deprecated and a new optionparams
orpathParams
can be introduced that automatically percent-encodes its values.The text was updated successfully, but these errors were encountered: