Skip to content

Commit 011e398

Browse files
committed
UriComponents formats Collection query param URI var
Closes gh-34311
1 parent 295a956 commit 011e398

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -48,7 +48,6 @@
4848
* @author Rossen Stoyanchev
4949
* @author Phillip Webb
5050
* @author Sam Brannen
51-
* @author Mengqi Xu
5251
* @since 3.1.3
5352
* @see <a href="https://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical URIs</a>
5453
*/
@@ -1092,8 +1091,8 @@ public QueryUriTemplateVariables(UriTemplateVariables delegate) {
10921091
if (ObjectUtils.isArray(value)) {
10931092
value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value));
10941093
}
1095-
if (value instanceof Collection<?> coll) {
1096-
value = StringUtils.collectionToCommaDelimitedString(coll);
1094+
else if (value instanceof Collection<?> collection) {
1095+
value = StringUtils.collectionToCommaDelimitedString(collection);
10971096
}
10981097
return value;
10991098
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -24,6 +24,7 @@
2424
import java.util.Arrays;
2525
import java.util.Collections;
2626
import java.util.List;
27+
import java.util.Map;
2728

2829
import org.junit.jupiter.api.Test;
2930
import org.junit.jupiter.params.ParameterizedTest;
@@ -157,22 +158,22 @@ void expandWithFragmentOrder(ParserType parserType) {
157158

158159
@Test
159160
void expandQueryParamWithArray() {
160-
UriComponents uri = UriComponentsBuilder.fromPath("/hello")
161+
String uri = UriComponentsBuilder.fromPath("/hello")
161162
.queryParam("name", "{name}")
162-
.build();
163-
uri = uri.expand(Collections.singletonMap("name", new String[]{"foo", "bar"}));
163+
.buildAndExpand(Map.of("name", new String[] {"foo", "bar"}))
164+
.toString();
164165

165-
assertThat(uri.toString()).hasToString("/hello?name=foo,bar");
166+
assertThat(uri).isEqualTo("/hello?name=foo,bar");
166167
}
167168

168169
@Test
169170
void expandQueryParamWithList() {
170-
UriComponents uri = UriComponentsBuilder.fromPath("/hello")
171+
String uri = UriComponentsBuilder.fromPath("/hello")
171172
.queryParam("name", "{name}")
172-
.build();
173-
uri = uri.expand(Collections.singletonMap("name", List.of("foo", "bar")));
173+
.buildAndExpand(Map.of("name", List.of("foo", "bar")))
174+
.toString();
174175

175-
assertThat(uri.toString()).hasToString("/hello?name=foo,bar");
176+
assertThat(uri).isEqualTo("/hello?name=foo,bar");
176177
}
177178

178179
@ParameterizedTest // SPR-12123

0 commit comments

Comments
 (0)