Skip to content

Commit e7d281c

Browse files
authored
allow single "=" as query (#5823)
* allow single = as query * unit test added * changelog added * changed the behavior * minor change * more test cases added
1 parent 6ae0dd4 commit e7d281c

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Fixed an issue in SdkHttpUtils used in SdkHttpFullRequest where constructing with a query string consisting of a single \"=\" would throw an ArrayIndexOutOfBoundsException."
6+
}

http-client-spi/src/test/java/software/amazon/awssdk/http/SdkHttpRequestResponseTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ public void testSdkHttpFullRequestBuilderUriWithQueryParamWithoutValue() {
412412
assertThat(actual.getUri()).hasToString(expected);
413413
}
414414

415+
@Test
416+
public void testSdkHttpFullRequestBuilderUriWithQueryParamWithoutValueWithEqual() {
417+
final String original = "https://github.com/aws/aws-sdk-for-java-v2?foo=";
418+
final String expected = "https://github.com/aws/aws-sdk-for-java-v2?foo";
419+
URI myUri = URI.create(original);
420+
421+
SdkHttpRequest actual = SdkHttpRequest.builder().method(SdkHttpMethod.POST).uri(myUri).build();
422+
assertThat(actual.getUri()).hasToString(expected);
423+
}
424+
415425
@Test
416426
public void testSdkHttpRequestBuilderNoQueryParams() {
417427
URI uri = URI.create("https://github.com/aws/aws-sdk-java-v2/issues/2034");
@@ -444,6 +454,16 @@ public void testSdkHttpRequestBuilderUriWithQueryParamWithoutValue() {
444454
assertThat(actual.getUri()).hasToString(expected);
445455
}
446456

457+
@Test
458+
public void testSdkHttpRequestWithSingleEqualQuery() {
459+
final String original = "http://example.com?=";
460+
final String expected = "http://example.com?";
461+
URI myUri = URI.create(original);
462+
463+
SdkHttpRequest actual = SdkHttpRequest.builder().method(SdkHttpMethod.POST).uri(myUri).build();
464+
assertThat(actual.getUri()).hasToString(expected);
465+
}
466+
447467
private interface BuilderProxy {
448468
BuilderProxy setValue(String key, String value);
449469

utils/src/main/java/software/amazon/awssdk/utils/http/SdkHttpUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ public static Map<String, List<String>> uriParams(URI uri) {
405405
return splitQueryString(uri.getRawQuery())
406406
.stream()
407407
.map(s -> s.split("="))
408+
.map(s -> s.length == 0 ? new String[] {""} : s)
408409
.map(s -> s.length == 1 ? new String[] { s[0], null } : s)
409410
.collect(groupingBy(a -> urlDecode(a[0]), mapping(a -> urlDecode(a[1]), toList())));
410411
}

utils/src/test/java/software/amazon/awssdk/utils/SdkHttpUtilsTest.java

+30
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,36 @@ public void uriParams() throws URISyntaxException {
238238
entry("decoded&Part", Arrays.asList("equals=val")));
239239
}
240240

241+
@Test
242+
void uriParamsWithSingleEqualQuery() {
243+
URI uri = URI.create("http://example.com?=");
244+
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
245+
assertThat(uriParams).containsKey("");
246+
assertThat(uriParams.get(""))
247+
.isNotNull()
248+
.hasSize(1)
249+
.containsNull();
250+
}
251+
@Test
252+
void uriParamsWithSingleEqualWithValueQuery() {
253+
URI uri = URI.create("http://example.com?=nokeyvalue");
254+
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
255+
assertThat(uriParams).containsKey("");
256+
assertThat(uriParams.get(""))
257+
.isNotNull()
258+
.hasSize(1)
259+
.contains("nokeyvalue");
260+
}
261+
@Test
262+
void uriParamsWithWithEmptyValueQuery() {
263+
URI uri = URI.create("http://example.com?novaluekey=");
264+
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
265+
assertThat(uriParams).containsKey("novaluekey");
266+
assertThat(uriParams.get("novaluekey"))
267+
.hasSize(1)
268+
.containsNull();
269+
}
270+
241271
@Test
242272
void parseSingleNonProxyHost(){
243273
String singleHostName = "singleHost" ;

0 commit comments

Comments
 (0)