Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 22, 2018 · 1 comment
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 22, 2018

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:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 23, 2018

Rossen Stoyanchev commented

This is another variation on the same root cause as #21997. It works as expected with the current 5.1.3 snapshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants