Skip to content

Commit 649bd3e

Browse files
Schäfer, H.H. (Hans Hosea)rstoyanchev
authored andcommitted
Do not clear queryParams UriComponentsBuilder#query
See gh-35628 Signed-off-by: Schäfer, H.H. (Hans Hosea) <HansHosea.Schaefer@ing.de>
1 parent 1c2a24a commit 649bd3e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,6 @@ public UriComponentsBuilder query(@Nullable String query) {
552552
}
553553
resetSchemeSpecificPart();
554554
}
555-
else {
556-
this.queryParams.clear();
557-
}
558555
return this;
559556
}
560557

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,24 @@ void replacePath(ParserType parserType) {
477477
assertThat(result.toUriString()).isEqualTo("https://www.ietf.org");
478478
}
479479

480+
@ParameterizedTest
481+
@EnumSource
482+
void query(final ParserType parserType) {
483+
final UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?foo=bar", parserType)
484+
.query("baz=qux")
485+
.build();
486+
assertThat(uriComponents.getQueryParams()).isEqualTo(Map.of("foo", List.of("bar"), "baz", List.of("qux")));
487+
}
488+
489+
@ParameterizedTest
490+
@EnumSource
491+
void queryWithNullDoesRetainQueryParameters(final ParserType parserType) {
492+
final UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?foo=bar", parserType)
493+
.query(null)
494+
.build();
495+
assertThat(uriComponents.getQueryParams()).isEqualTo(Map.of("foo", List.of("bar")));
496+
}
497+
480498
@ParameterizedTest
481499
@EnumSource
482500
void replaceQuery(ParserType parserType) {

0 commit comments

Comments
 (0)