Skip to content

Commit

Permalink
Merge branch '6.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Jan 2, 2025
2 parents 69b7624 + d927d64 commit b6de2b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -464,16 +464,14 @@ private String appendQueryParams(
String uriTemplate, Map<String, String> uriVars, MultiValueMap<String, String> requestParams) {

UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(uriTemplate);
int i = 0;
for (Map.Entry<String, List<String>> entry : requestParams.entrySet()) {
String nameVar = "queryParam" + i;
String nameVar = entry.getKey();
uriVars.put(nameVar, entry.getKey());
for (int j = 0; j < entry.getValue().size(); j++) {
String valueVar = nameVar + "[" + j + "]";
uriVars.put(valueVar, entry.getValue().get(j));
uriComponentsBuilder.queryParam("{" + nameVar + "}", "{" + valueVar + "}");
}
i++;
}
return uriComponentsBuilder.build().toUriString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,17 +79,17 @@ void queryParamsWithUriTemplate() {

assertThat(uriTemplate)
.isEqualTo("/path?" +
"{queryParam0}={queryParam0[0]}&" +
"{queryParam1}={queryParam1[0]}&" +
"{queryParam1}={queryParam1[1]}");
"{param1}={param1[0]}&" +
"{param2}={param2[0]}&" +
"{param2}={param2[1]}");

assertThat(requestValues.getUriVariables())
.containsOnlyKeys("queryParam0", "queryParam1", "queryParam0[0]", "queryParam1[0]", "queryParam1[1]")
.containsEntry("queryParam0", "param1")
.containsEntry("queryParam1", "param2")
.containsEntry("queryParam0[0]", "1st value")
.containsEntry("queryParam1[0]", "2nd value A")
.containsEntry("queryParam1[1]", "2nd value B");
.containsOnlyKeys("param1", "param2", "param1[0]", "param2[0]", "param2[1]")
.containsEntry("param1", "param1")
.containsEntry("param2", "param2")
.containsEntry("param1[0]", "1st value")
.containsEntry("param2[0]", "2nd value A")
.containsEntry("param2[1]", "2nd value B");

URI uri = UriComponentsBuilder.fromUriString(uriTemplate)
.encode()
Expand Down Expand Up @@ -144,7 +144,13 @@ void requestPartAndRequestParam() {
String uriTemplate = requestValues.getUriTemplate();
assertThat(uriTemplate).isNotNull();

assertThat(uriTemplate).isEqualTo("/path?{queryParam0}={queryParam0[0]}");
assertThat(uriTemplate).isEqualTo("/path?{query param}={query param[0]}");

URI uri = UriComponentsBuilder.fromUriString(uriTemplate)
.encode()
.build(requestValues.getUriVariables());
assertThat(uri.toString())
.isEqualTo("/path?query%20param=query%20value");

@SuppressWarnings("unchecked")
MultiValueMap<String, Object> map = (MultiValueMap<String, Object>) requestValues.getBodyValue();
Expand Down

0 comments on commit b6de2b0

Please sign in to comment.