Skip to content

Commit ab6b504

Browse files
committed
Copy queryParams MultiValueMap through addAll (for independent List entries)
Closes gh-25423
1 parent 515bae9 commit ab6b504

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -153,7 +153,7 @@ protected UriComponentsBuilder(UriComponentsBuilder other) {
153153
this.port = other.port;
154154
this.pathBuilder = other.pathBuilder.cloneBuilder();
155155
this.uriVariables.putAll(other.uriVariables);
156-
this.queryParams.putAll(other.queryParams);
156+
this.queryParams.addAll(other.queryParams);
157157
this.fragment = other.fragment;
158158
this.encodeTemplate = other.encodeTemplate;
159159
this.charset = other.charset;

spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -752,30 +752,32 @@ public void parsesEmptyUri() {
752752
assertThat(components.toString(), equalTo(""));
753753
}
754754

755-
@Test
755+
@Test // gh-25243
756756
public void testCloneAndMerge() {
757757
UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance();
758-
builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1").fragment("f1").encode();
758+
builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1", "x").fragment("f1").encode();
759759

760-
UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone();
760+
UriComponentsBuilder builder2 = builder1.cloneBuilder();
761761
builder2.scheme("https").host("e2.com").path("p2").pathSegment("{ps2}").queryParam("q2").fragment("f2");
762762

763+
builder1.queryParam("q1", "y"); // one more entry for an existing parameter
764+
763765
UriComponents result1 = builder1.build();
764766
assertEquals("http", result1.getScheme());
765767
assertEquals("e1.com", result1.getHost());
766768
assertEquals("/p1/ps1", result1.getPath());
767-
assertEquals("q1", result1.getQuery());
769+
assertEquals("q1=x&q1=y", result1.getQuery());
768770
assertEquals("f1", result1.getFragment());
769771

770772
UriComponents result2 = builder2.buildAndExpand("ps2;a");
771773
assertEquals("https", result2.getScheme());
772774
assertEquals("e2.com", result2.getHost());
773775
assertEquals("/p1/ps1/p2/ps2%3Ba", result2.getPath());
774-
assertEquals("q1&q2", result2.getQuery());
776+
assertEquals("q1=x&q2", result2.getQuery());
775777
assertEquals("f2", result2.getFragment());
776778
}
777779

778-
@Test // gh-24772
780+
@Test // gh-24772
779781
public void testDeepClone() {
780782
HashMap<String, Object> vars = new HashMap<>();
781783
vars.put("ps1", "foo");
@@ -785,7 +787,7 @@ public void testDeepClone() {
785787
builder1.scheme("http").host("e1.com").userInfo("user:pwd").path("/p1").pathSegment("{ps1}")
786788
.pathSegment("{ps2}").queryParam("q1").fragment("f1").uriVariables(vars).encode();
787789

788-
UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone();
790+
UriComponentsBuilder builder2 = builder1.cloneBuilder();
789791

790792
UriComponents result1 = builder1.build();
791793
assertEquals("http", result1.getScheme());

0 commit comments

Comments
 (0)