Configuring a RestTemplate with EncodingMode.VALUES_ONLY does not encode special characters [SPR-17048] #21586
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: invalid
An issue that we don't feel is valid
Etienne Dysli Metref opened SPR-17048 and commented
Contrary to what Spring Web's documentation states, changing the encoding method by configuring the
DefaultUriBuilderFactory
used byRestTemplate
withsetEncodingMode(EncodingMode.VALUES_ONLY)
does not have the expected effect. It should "apply UriUtils.encode(String, Charset) to each URI variable value" which in turn will "encode all characters that are either illegal, or have any reserved meaning, anywhere within a URI, as defined in RFC 3986". However I'm still seeing+
,:
or/
in query parameter values that are not %-encoded.The following test case fails with
java.lang.AssertionError: Request URI expected:<[https://host?parameter=%2B%3A%2F](https://host/?parameter=%2B%3A%2F)> but was:<[https://host?parameter=+:/](https://host/?parameter=+:/)>
. (executing it with dependencies org.springframework.boot:spring-boot-starter:2.0.3.RELEASE, org.springframework:spring-web:5.0.7.RELEASE, org.springframework.boot:spring-boot-starter-test:2.0.3.RELEASE)Affects: 5.0.7
Reference URL: https://stackoverflow.com/questions/51241321/how-to-have-a-resttemplate-encode-all-characters-with-uricomponents-and-encoding
The text was updated successfully, but these errors were encountered: