Skip to content

Commit 94ac2e4

Browse files
committed
Fix UriComponentsBuilder examples in ref docs
Closes gh-26453
1 parent 271a909 commit 94ac2e4

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,6 +49,27 @@
4949
*/
5050
class UriComponentsBuilderTests {
5151

52+
@Test // see gh-26453
53+
void examplesInReferenceManual() {
54+
final String expected = "/hotel%20list/New%20York?q=foo%2Bbar";
55+
56+
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
57+
.queryParam("q", "{q}")
58+
.encode()
59+
.buildAndExpand("New York", "foo+bar")
60+
.toUri();
61+
assertThat(uri).asString().isEqualTo(expected);
62+
63+
uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
64+
.queryParam("q", "{q}")
65+
.build("New York", "foo+bar");
66+
assertThat(uri).asString().isEqualTo(expected);
67+
68+
uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
69+
.build("New York", "foo+bar");
70+
assertThat(uri).asString().isEqualTo(expected);
71+
}
72+
5273
@Test
5374
void plain() throws URISyntaxException {
5475
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();

src/docs/asciidoc/web/web-uris.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ as the following example shows:
8282
.build("Westin", "123")
8383
----
8484

85-
You shorter it further still with a full URI template, as the following example shows:
85+
You can shorten it further still with a full URI template, as the following example shows:
8686

8787
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
8888
.Java
@@ -94,7 +94,7 @@ You shorter it further still with a full URI template, as the following example
9494
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
9595
.Kotlin
9696
----
97-
val uri = UriComponentsBuilder
97+
val uri = UriComponentsBuilder
9898
.fromUriString("https://example.com/hotels/{hotel}?q={q}")
9999
.build("Westin", "123")
100100
----
@@ -250,7 +250,7 @@ as the following example shows:
250250
----
251251
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
252252
.queryParam("q", "{q}")
253-
.build("New York", "foo+bar")
253+
.build("New York", "foo+bar");
254254
----
255255
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
256256
.Kotlin
@@ -265,13 +265,13 @@ You can shorten it further still with a full URI template, as the following exam
265265
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
266266
.Java
267267
----
268-
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
269-
.build("New York", "foo+bar")
268+
URI uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
269+
.build("New York", "foo+bar");
270270
----
271271
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
272272
.Kotlin
273273
----
274-
val uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
274+
val uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
275275
.build("New York", "foo+bar")
276276
----
277277

0 commit comments

Comments
 (0)