Polishing contribution
Closes gh-34783
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -451,11 +451,10 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
UriTemplateVariables queryVariables = new QueryUriTemplateVariables(variables);
|
||||
this.queryParams.forEach((key, values) -> {
|
||||
String name = expandUriComponent(key, queryVariables, this.variableEncoder);
|
||||
List<String> expandedValues = result.getOrDefault(name, new ArrayList<>(values.size()));
|
||||
List<String> expandedValues = result.computeIfAbsent(name, k -> new ArrayList<>(values.size()));
|
||||
for (String value : values) {
|
||||
expandedValues.add(expandUriComponent(value, queryVariables, this.variableEncoder));
|
||||
}
|
||||
result.put(name, expandedValues);
|
||||
});
|
||||
return CollectionUtils.unmodifiableMultiValueMap(result);
|
||||
}
|
||||
|
||||
@@ -629,18 +629,15 @@ class UriComponentsBuilderTests {
|
||||
assertThat(uri.toString()).isEqualTo("ws://example.org:7777/path?q=1#foo");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ParameterizedTest // gh-34783
|
||||
@EnumSource
|
||||
void parseBuildAndExpandHierarchicalWithDuplicateQueryKeys(ParserType parserType) {
|
||||
UriComponents result = UriComponentsBuilder.fromUriString("/?{pk1}={pv1}&{pk2}={pv2}", parserType)
|
||||
void parseBuildAndExpandQueryParamWithSameName(ParserType parserType) {
|
||||
UriComponents result = UriComponentsBuilder
|
||||
.fromUriString("/?{pk1}={pv1}&{pk2}={pv2}", parserType)
|
||||
.buildAndExpand("k1", "v1", "k1", "v2");
|
||||
assertThat(result.getQuery()).isEqualTo("k1=v1&k1=v2");
|
||||
assertThat(result.getQueryParams().get("k1")).containsExactly("v1", "v2");
|
||||
|
||||
UriComponents result2 = UriComponentsBuilder.fromUriString("/?{pk1}={pv1}&{pk2}={pv2}", parserType)
|
||||
.buildAndExpand(Map.of("pk1", "k1", "pv1", "v1", "pk2", "k1", "pv2", "v2"));
|
||||
assertThat(result2.getQuery()).isEqualTo("k1=v1&k1=v2");
|
||||
assertThat(result.getQueryParams().get("k1")).containsExactly("v1", "v2");
|
||||
assertThat(result.getQuery()).isEqualTo("k1=v1&k1=v2");
|
||||
assertThat(result.getQueryParams()).containsExactly(Map.entry("k1", List.of("v1", "v2")));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
Reference in New Issue
Block a user