Description
Describe the bug
I use the following version of Spring Cloud Gateway MVC to forward request.
org.springframework.cloud
spring-cloud-starter-gateway-mvc
4.1.2
same description as #3272
a bug in the code of the ProxyExchangeHandlerFunction class.
boolean encoded = containsEncodedQuery(serverRequest.uri());
// @formatter:off
URI url = UriComponentsBuilder.fromUri(serverRequest.uri())
.scheme(uri.getScheme())
.host(uri.getHost())
.port(uri.getPort())
.replaceQueryParams(serverRequest.params())
.build(encoded)
.toUri();
This is based on serverRequest.uri() to determine whether the URL has been encoded, but when constructing a new URL, the query parameter is replaced with serverRequest.params(). The reality is that serverRequest.uri() is encoded by the URI, but serverRequest.params() is not encoded.
Sample
The url as http://localhost:8083/test?q=name%3Atestname%2BState%3AFailed
In Gateway MVC will forward the rquest as
http://localhost:8083/test?q=name:testname+State:Failed, when the corrsponding service receive the request,
then + becomes space character.
For the UriComponentsBuilder, it will use HierarchicalUriComponents internally, is this related to below issue?
spring-projects/spring-framework#23025