Skip to content

WebClient no longer encodes query parameters [SPR-17532] #22064

Closed
@spring-projects-issues

Description

@spring-projects-issues

ShaManHFel opened SPR-17532 and commented

The following sample code used to work in 5.0.8 but stopped working in 5.1.2:

 

WebClient.builder()
.baseUrl("https://www.google.com")
.build()
.get()
.uri(builder -> builder
.path("search")
*.queryParam("q", "some spaces in the value")*
.build())
.retrieve()
.bodyToMono(String.class)
.block();{color}

 

In 5.0.8 the result from this code was the following call:

GET /search?q=some%20spaces%20in%20the%20value HTTP/1.1
user-agent: ReactorNetty/0.7.8.RELEASE
host: [www.google.com](http://www.google.com/)

In 5.1.2 the result is:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 36: https://www.google.com/search?q=some spaces in the value
at java.net.URI.create(URI.java:852)
at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.createUri(DefaultUriBuilderFactory.java:391)
at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.build(DefaultUriBuilderFactory.java:384)
at com.vmware.identity.SpringBug.lambda$main$0(SpringBug.java:19)
at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:189)
at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:153)
at com.vmware.identity.SpringBug.main(SpringBug.java:16)
Caused by: java.net.URISyntaxException: Illegal character in query at index 36: https://www.google.com/search?q=some spaces in the value
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3111)
at java.net.URI$Parser.parse(URI.java:3053)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 6 more

As evident from the error, the queryParam() method no longer encodes the query parameter values. This seems to be caused by a change in DefaultUriBuilderFactory where the default encoding mode was changed ``to EncodingMode.TEMPLATE_AND_VALUES.


Affects: 5.1.2

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions