ITADN

URL model double encoding issue

#3887Opendutch3883 创建于 2026-01-12
bug
D
dutch3883commented
I found a strange behavior when using `zio-http` to parse a URL and return a redirect response. My original input to Response.redirect was of type `sttp.model.Uri`, so I converted it to a Java URI and then used `zio.http.URL.fromURI` to create the expected input type. However, the redirected URL ended up being double-encoded. Example: http://testsample.com/file/test%20hotel.pdf becomes http://testsample.com/file/test%2520hotel.pdf (where % is re-encoded as %25) After investigating, I found two potential causes: In the `fromAbsoluteURI` constructor, `getRawPath` is used. This returns an already-encoded path and stores it as the case class value. This part seems fine. In the `.toString` method (which I assume is used when converting the URL into a response), it appears that encoding is applied again internally. This seems to be where the double-encoding happens. You can reproduce it with this snippet: URL.decode("http://testsample.com/file/test%20hotel.pdf").toString and refer failed test https://github.com/zio/zio-http/actions/runs/20910888749/job/60073381862?pr=3886
0 条评论