File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
main/java/org/springframework/web/util
test/java/org/springframework/web/util Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 2222import java .net .URISyntaxException ;
2323import java .nio .charset .Charset ;
2424import java .util .ArrayList ;
25+ import java .util .Collection ;
2526import java .util .Collections ;
2627import java .util .List ;
2728import java .util .Objects ;
4748 * @author Rossen Stoyanchev
4849 * @author Phillip Webb
4950 * @author Sam Brannen
51+ * @author Mengqi Xu
5052 * @since 3.1.3
5153 * @see <a href="https://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical URIs</a>
5254 */
@@ -1090,6 +1092,9 @@ public QueryUriTemplateVariables(UriTemplateVariables delegate) {
10901092 if (ObjectUtils .isArray (value )) {
10911093 value = StringUtils .arrayToCommaDelimitedString (ObjectUtils .toObjectArray (value ));
10921094 }
1095+ if (value instanceof Collection <?> coll ) {
1096+ value = StringUtils .collectionToCommaDelimitedString (coll );
1097+ }
10931098 return value ;
10941099 }
10951100 }
Original file line number Diff line number Diff line change 2323import java .net .URI ;
2424import java .util .Arrays ;
2525import java .util .Collections ;
26+ import java .util .List ;
2627
2728import org .junit .jupiter .api .Test ;
2829import org .junit .jupiter .params .ParameterizedTest ;
4243 * @author Arjen Poutsma
4344 * @author Phillip Webb
4445 * @author Rossen Stoyanchev
46+ * @author Mengqi Xu
4547 */
4648class UriComponentsTests {
4749
@@ -153,6 +155,26 @@ void expandWithFragmentOrder(ParserType parserType) {
153155 assertThat (uri .toUriString ()).isEqualTo ("https://example.com/foo#bar" );
154156 }
155157
158+ @ Test
159+ void expandQueryParamWithArray () {
160+ UriComponents uri = UriComponentsBuilder .fromPath ("/hello" )
161+ .queryParam ("name" , "{name}" )
162+ .build ();
163+ uri = uri .expand (Collections .singletonMap ("name" , new String []{"foo" , "bar" }));
164+
165+ assertThat (uri .toString ()).hasToString ("/hello?name=foo,bar" );
166+ }
167+
168+ @ Test
169+ void expandQueryParamWithList () {
170+ UriComponents uri = UriComponentsBuilder .fromPath ("/hello" )
171+ .queryParam ("name" , "{name}" )
172+ .build ();
173+ uri = uri .expand (Collections .singletonMap ("name" , List .of ("foo" , "bar" )));
174+
175+ assertThat (uri .toString ()).hasToString ("/hello?name=foo,bar" );
176+ }
177+
156178 @ ParameterizedTest // SPR-12123
157179 @ EnumSource
158180 void port (ParserType parserType ) {
You can’t perform that action at this time.
0 commit comments