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 22
22
import java .net .URISyntaxException ;
23
23
import java .nio .charset .Charset ;
24
24
import java .util .ArrayList ;
25
+ import java .util .Collection ;
25
26
import java .util .Collections ;
26
27
import java .util .List ;
27
28
import java .util .Objects ;
47
48
* @author Rossen Stoyanchev
48
49
* @author Phillip Webb
49
50
* @author Sam Brannen
51
+ * @author Mengqi Xu
50
52
* @since 3.1.3
51
53
* @see <a href="https://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical URIs</a>
52
54
*/
@@ -1090,6 +1092,9 @@ public QueryUriTemplateVariables(UriTemplateVariables delegate) {
1090
1092
if (ObjectUtils .isArray (value )) {
1091
1093
value = StringUtils .arrayToCommaDelimitedString (ObjectUtils .toObjectArray (value ));
1092
1094
}
1095
+ if (value instanceof Collection <?> coll ) {
1096
+ value = StringUtils .collectionToCommaDelimitedString (coll );
1097
+ }
1093
1098
return value ;
1094
1099
}
1095
1100
}
Original file line number Diff line number Diff line change 23
23
import java .net .URI ;
24
24
import java .util .Arrays ;
25
25
import java .util .Collections ;
26
+ import java .util .List ;
26
27
27
28
import org .junit .jupiter .api .Test ;
28
29
import org .junit .jupiter .params .ParameterizedTest ;
42
43
* @author Arjen Poutsma
43
44
* @author Phillip Webb
44
45
* @author Rossen Stoyanchev
46
+ * @author Mengqi Xu
45
47
*/
46
48
class UriComponentsTests {
47
49
@@ -153,6 +155,26 @@ void expandWithFragmentOrder(ParserType parserType) {
153
155
assertThat (uri .toUriString ()).isEqualTo ("https://example.com/foo#bar" );
154
156
}
155
157
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
+
156
178
@ ParameterizedTest // SPR-12123
157
179
@ EnumSource
158
180
void port (ParserType parserType ) {
You can’t perform that action at this time.
0 commit comments