Skip to content

Commit

Permalink
Copy queryParams MultiValueMap through addAll (for independent List e…
Browse files Browse the repository at this point in the history
…ntries)

Closes gh-25423
  • Loading branch information
jhoeller committed Jul 20, 2020
1 parent f1345aa commit 65e6010
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Expand Up @@ -157,7 +157,7 @@ protected UriComponentsBuilder(UriComponentsBuilder other) {
this.port = other.port;
this.pathBuilder = other.pathBuilder.cloneBuilder();
this.uriVariables.putAll(other.uriVariables);
this.queryParams.putAll(other.queryParams);
this.queryParams.addAll(other.queryParams);
this.fragment = other.fragment;
this.encodeTemplate = other.encodeTemplate;
this.charset = other.charset;
Expand Down
Expand Up @@ -918,30 +918,32 @@ void parsesEmptyUri() {
assertThat(components.toString()).isEqualTo("");
}

@Test
@Test // gh-25243
void testCloneAndMerge() {
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");

builder1.queryParam("q1", "y"); // one more entry for an existing parameter

UriComponents result1 = builder1.build();
assertThat(result1.getScheme()).isEqualTo("http");
assertThat(result1.getHost()).isEqualTo("e1.com");
assertThat(result1.getPath()).isEqualTo("/p1/ps1");
assertThat(result1.getQuery()).isEqualTo("q1");
assertThat(result1.getQuery()).isEqualTo("q1=x&q1=y");
assertThat(result1.getFragment()).isEqualTo("f1");

UriComponents result2 = builder2.buildAndExpand("ps2;a");
assertThat(result2.getScheme()).isEqualTo("https");
assertThat(result2.getHost()).isEqualTo("e2.com");
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");
}

@Test // gh-24772
@Test // gh-24772
void testDeepClone() {
HashMap<String, Object> vars = new HashMap<>();
vars.put("ps1", "foo");
Expand All @@ -951,7 +953,7 @@ void testDeepClone() {
builder1.scheme("http").host("e1.com").userInfo("user:pwd").path("/p1").pathSegment("{ps1}")
.pathSegment("{ps2}").queryParam("q1").fragment("f1").uriVariables(vars).encode();

UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone();
UriComponentsBuilder builder2 = builder1.cloneBuilder();

UriComponents result1 = builder1.build();
assertThat(result1.getScheme()).isEqualTo("http");
Expand Down

0 comments on commit 65e6010

Please sign in to comment.