Copy queryParams MultiValueMap through addAll (for independent List entries)
Closes gh-25423
This commit is contained in:
parent
f1345aadf5
commit
65e601090f
|
|
@ -157,7 +157,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||||
this.port = other.port;
|
this.port = other.port;
|
||||||
this.pathBuilder = other.pathBuilder.cloneBuilder();
|
this.pathBuilder = other.pathBuilder.cloneBuilder();
|
||||||
this.uriVariables.putAll(other.uriVariables);
|
this.uriVariables.putAll(other.uriVariables);
|
||||||
this.queryParams.putAll(other.queryParams);
|
this.queryParams.addAll(other.queryParams);
|
||||||
this.fragment = other.fragment;
|
this.fragment = other.fragment;
|
||||||
this.encodeTemplate = other.encodeTemplate;
|
this.encodeTemplate = other.encodeTemplate;
|
||||||
this.charset = other.charset;
|
this.charset = other.charset;
|
||||||
|
|
|
||||||
|
|
@ -918,26 +918,28 @@ class UriComponentsBuilderTests {
|
||||||
assertThat(components.toString()).isEqualTo("");
|
assertThat(components.toString()).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // gh-25243
|
||||||
void testCloneAndMerge() {
|
void testCloneAndMerge() {
|
||||||
UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance();
|
UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance();
|
||||||
builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1").fragment("f1").encode();
|
builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1", "x").fragment("f1").encode();
|
||||||
|
|
||||||
UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone();
|
UriComponentsBuilder builder2 = builder1.cloneBuilder();
|
||||||
builder2.scheme("https").host("e2.com").path("p2").pathSegment("{ps2}").queryParam("q2").fragment("f2");
|
builder2.scheme("https").host("e2.com").path("p2").pathSegment("{ps2}").queryParam("q2").fragment("f2");
|
||||||
|
|
||||||
|
builder1.queryParam("q1", "y"); // one more entry for an existing parameter
|
||||||
|
|
||||||
UriComponents result1 = builder1.build();
|
UriComponents result1 = builder1.build();
|
||||||
assertThat(result1.getScheme()).isEqualTo("http");
|
assertThat(result1.getScheme()).isEqualTo("http");
|
||||||
assertThat(result1.getHost()).isEqualTo("e1.com");
|
assertThat(result1.getHost()).isEqualTo("e1.com");
|
||||||
assertThat(result1.getPath()).isEqualTo("/p1/ps1");
|
assertThat(result1.getPath()).isEqualTo("/p1/ps1");
|
||||||
assertThat(result1.getQuery()).isEqualTo("q1");
|
assertThat(result1.getQuery()).isEqualTo("q1=x&q1=y");
|
||||||
assertThat(result1.getFragment()).isEqualTo("f1");
|
assertThat(result1.getFragment()).isEqualTo("f1");
|
||||||
|
|
||||||
UriComponents result2 = builder2.buildAndExpand("ps2;a");
|
UriComponents result2 = builder2.buildAndExpand("ps2;a");
|
||||||
assertThat(result2.getScheme()).isEqualTo("https");
|
assertThat(result2.getScheme()).isEqualTo("https");
|
||||||
assertThat(result2.getHost()).isEqualTo("e2.com");
|
assertThat(result2.getHost()).isEqualTo("e2.com");
|
||||||
assertThat(result2.getPath()).isEqualTo("/p1/ps1/p2/ps2%3Ba");
|
assertThat(result2.getPath()).isEqualTo("/p1/ps1/p2/ps2%3Ba");
|
||||||
assertThat(result2.getQuery()).isEqualTo("q1&q2");
|
assertThat(result2.getQuery()).isEqualTo("q1=x&q2");
|
||||||
assertThat(result2.getFragment()).isEqualTo("f2");
|
assertThat(result2.getFragment()).isEqualTo("f2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -951,7 +953,7 @@ class UriComponentsBuilderTests {
|
||||||
builder1.scheme("http").host("e1.com").userInfo("user:pwd").path("/p1").pathSegment("{ps1}")
|
builder1.scheme("http").host("e1.com").userInfo("user:pwd").path("/p1").pathSegment("{ps1}")
|
||||||
.pathSegment("{ps2}").queryParam("q1").fragment("f1").uriVariables(vars).encode();
|
.pathSegment("{ps2}").queryParam("q1").fragment("f1").uriVariables(vars).encode();
|
||||||
|
|
||||||
UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone();
|
UriComponentsBuilder builder2 = builder1.cloneBuilder();
|
||||||
|
|
||||||
UriComponents result1 = builder1.build();
|
UriComponents result1 = builder1.build();
|
||||||
assertThat(result1.getScheme()).isEqualTo("http");
|
assertThat(result1.getScheme()).isEqualTo("http");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue