Skip to content

Commit

Permalink
allow single "=" as query (#5823)
Browse files Browse the repository at this point in the history
* allow single = as query

* unit test added

* changelog added

* changed the behavior

* minor change

* more test cases added
  • Loading branch information
Fred1155 authored Jan 30, 2025
1 parent 6ae0dd4 commit e7d281c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-466bf4c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Fixed an issue in SdkHttpUtils used in SdkHttpFullRequest where constructing with a query string consisting of a single \"=\" would throw an ArrayIndexOutOfBoundsException."
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ public void testSdkHttpFullRequestBuilderUriWithQueryParamWithoutValue() {
assertThat(actual.getUri()).hasToString(expected);
}

@Test
public void testSdkHttpFullRequestBuilderUriWithQueryParamWithoutValueWithEqual() {
final String original = "https://github.com/aws/aws-sdk-for-java-v2?foo=";
final String expected = "https://github.com/aws/aws-sdk-for-java-v2?foo";
URI myUri = URI.create(original);

SdkHttpRequest actual = SdkHttpRequest.builder().method(SdkHttpMethod.POST).uri(myUri).build();
assertThat(actual.getUri()).hasToString(expected);
}

@Test
public void testSdkHttpRequestBuilderNoQueryParams() {
URI uri = URI.create("https://github.com/aws/aws-sdk-java-v2/issues/2034");
Expand Down Expand Up @@ -444,6 +454,16 @@ public void testSdkHttpRequestBuilderUriWithQueryParamWithoutValue() {
assertThat(actual.getUri()).hasToString(expected);
}

@Test
public void testSdkHttpRequestWithSingleEqualQuery() {
final String original = "http://example.com?=";
final String expected = "http://example.com?";
URI myUri = URI.create(original);

SdkHttpRequest actual = SdkHttpRequest.builder().method(SdkHttpMethod.POST).uri(myUri).build();
assertThat(actual.getUri()).hasToString(expected);
}

private interface BuilderProxy {
BuilderProxy setValue(String key, String value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public static Map<String, List<String>> uriParams(URI uri) {
return splitQueryString(uri.getRawQuery())
.stream()
.map(s -> s.split("="))
.map(s -> s.length == 0 ? new String[] {""} : s)
.map(s -> s.length == 1 ? new String[] { s[0], null } : s)
.collect(groupingBy(a -> urlDecode(a[0]), mapping(a -> urlDecode(a[1]), toList())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,36 @@ public void uriParams() throws URISyntaxException {
entry("decoded&Part", Arrays.asList("equals=val")));
}

@Test
void uriParamsWithSingleEqualQuery() {
URI uri = URI.create("http://example.com?=");
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
assertThat(uriParams).containsKey("");
assertThat(uriParams.get(""))
.isNotNull()
.hasSize(1)
.containsNull();
}
@Test
void uriParamsWithSingleEqualWithValueQuery() {
URI uri = URI.create("http://example.com?=nokeyvalue");
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
assertThat(uriParams).containsKey("");
assertThat(uriParams.get(""))
.isNotNull()
.hasSize(1)
.contains("nokeyvalue");
}
@Test
void uriParamsWithWithEmptyValueQuery() {
URI uri = URI.create("http://example.com?novaluekey=");
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
assertThat(uriParams).containsKey("novaluekey");
assertThat(uriParams.get("novaluekey"))
.hasSize(1)
.containsNull();
}

@Test
void parseSingleNonProxyHost(){
String singleHostName = "singleHost" ;
Expand Down

0 comments on commit e7d281c

Please sign in to comment.