spring-cloud / spring-cloud/spring-cloud-gateway

rewritePath function in BeforeFilterFunctions doesn't support url encoded

Open
#3,657 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.