Skip to content

Commit ffcbd2e

Browse files
Schäfer, H.H. (Hans Hosea)Schäfer, H.H. (Hans Hosea)
authored andcommitted
35628: UriComponentsBuilder: Do not clear queryparams in method query which is intended for adding values
1 parent 2591cab commit ffcbd2e

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
@@ -607,9 +607,6 @@ public UriComponentsBuilder query(@Nullable String query) {
607607
}
608608
resetSchemeSpecificPart();
609609
}
610-
else {
611-
this.queryParams.clear();
612-
}
613610
return this;
614611
}
615612

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)