Affects: 5.3.x and potentially earlier releases
In src/docs/asciidoc/web/web-uris.adoc
(https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#web-uri-encoding )
I think there is a bug in the example right after the following text "You can shorten it further still with a full URI template, as the following example shows:"
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
.build("New York", "foo+bar")
should be
URI uri = UriComponentsBuilder.fromStringUri("/hotel list/{city}?q={q}")
.build("New York", "foo+bar")
See in jshell:
jshell> UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}") .build("New York", "foo+bar")
$37 ==> /hotel%20list/New%20York%3Fq=foo%2Bbar
jshell> UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}") .build("New York", "foo+bar")
$38 ==> /hotel%20list/New%20York?q=foo%2Bbar
In the first case, the question mark indicating the beginning of the query string has been incorrectly escaped.
Comment From: sbrannen
Good catch!
That does indeed need to be fromUriString
(not fromPath
or fromStringUri
).
We'll get that fixed.