Skip to content

UriComponentsBuilder documentation error for HTTP request encoding #26453

@jonenst

Description

@jonenst

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.

Metadata

Metadata

Assignees

Labels

status: backportedAn issue that has been backported to maintenance branchestype: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions