spring-cloud / spring-cloud/spring-cloud-gateway
rewritePath function in BeforeFilterFunctions doesn't support url encoded
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Describe the bug
I'm using the function rewritePath in org.springframework.cloud.gatexay.server.mvc.BeforeFilterFunctions in a RouterFunction policy. It works well excepts when the url contains an encoded character.
With an encoded character (ex /testé), the output url will transform as /test%25C3%25A9 instead of /test%C3%A9.
In fact, in the rewritePath method, it doesn't take into account the encoded url :
URI rewrittenUri = UriComponentsBuilder.fromUri(request.uri()).replacePath(newPath).build().toUri();
It works well with :
URI rewrittenUri = UriComponentsBuilder.fromUri(request.uri()).replacePath(newPath).build(true).toUri();
Is it intended that the rewritePath method be written like this ? or is it a bug ?
Test case
call the gateway app with an accentuated character in the url (ex: GET /testé). your http client librairie will encoded the url as GET /test%C3%A9. and the output will be /test%25C3%25A9.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the rewritePath function in org.springframework.cloud.gateway.server.mvc.BeforeFilterFunctions and reproduce the request described with an encoded path such as /test%C3%A9. Compare the rewritten URI with the expected single-encoded path, then verify the behavior with a regression test covering an accented URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100