UriComponentsBuilder copies query params through MultiValueMap.addAll
Issue: SPR-17256
This commit is contained in:
@@ -119,7 +119,6 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
|
|||||||
public Map<K, V> toSingleValueMap() {
|
public Map<K, V> toSingleValueMap() {
|
||||||
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.targetMap.size());
|
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.targetMap.size());
|
||||||
this.targetMap.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
|
this.targetMap.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
|
||||||
|
|
||||||
return singleValueMap;
|
return singleValueMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +192,10 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
|
|||||||
/**
|
/**
|
||||||
* Create a deep copy of this Map.
|
* Create a deep copy of this Map.
|
||||||
* @return a copy of this Map, including a copy of each value-holding List entry
|
* @return a copy of this Map, including a copy of each value-holding List entry
|
||||||
|
* (consistently using an independent modifiable {@link LinkedList} for each entry)
|
||||||
|
* along the lines of {@code MultiValueMap.addAll} semantics
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
|
* @see #addAll(MultiValueMap)
|
||||||
* @see #clone()
|
* @see #clone()
|
||||||
*/
|
*/
|
||||||
public LinkedMultiValueMap<K, V> deepCopy() {
|
public LinkedMultiValueMap<K, V> deepCopy() {
|
||||||
@@ -205,7 +207,11 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
|
|||||||
/**
|
/**
|
||||||
* Create a regular copy of this Map.
|
* Create a regular copy of this Map.
|
||||||
* @return a shallow copy of this Map, reusing this Map's value-holding List entries
|
* @return a shallow copy of this Map, reusing this Map's value-holding List entries
|
||||||
|
* (even if some entries are shared or unmodifiable) along the lines of standard
|
||||||
|
* {@code Map.put} semantics
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
|
* @see #put(Object, List)
|
||||||
|
* @see #putAll(Map)
|
||||||
* @see LinkedMultiValueMap#LinkedMultiValueMap(Map)
|
* @see LinkedMultiValueMap#LinkedMultiValueMap(Map)
|
||||||
* @see #deepCopy()
|
* @see #deepCopy()
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -705,7 +705,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
|||||||
@Override
|
@Override
|
||||||
public UriComponentsBuilder queryParams(@Nullable MultiValueMap<String, String> params) {
|
public UriComponentsBuilder queryParams(@Nullable MultiValueMap<String, String> params) {
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
this.queryParams.putAll(params);
|
this.queryParams.addAll(params);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -922,4 +922,11 @@ public class UriComponentsBuilderTests {
|
|||||||
assertNotEquals(uri1, uri2);
|
assertNotEquals(uri1, uri2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // SPR-17256
|
||||||
|
public void uriComponentsWithQueryParamClone() {
|
||||||
|
UriComponentsBuilder.fromUriString("http://localhost:8081")
|
||||||
|
.uriComponents(UriComponentsBuilder.fromUriString("/{path}?sort={sort}").build())
|
||||||
|
.queryParam("sort", "another_value").build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user