Skip to content

allow single "=" as query #5823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the bug \"ArrayIndexOutOfBoundsException\" when single \"=\" as the query string"
Copy link
Contributor

@joviegas joviegas Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be specific about the fix is made in SdkHttpFullRequest

Fixed an issue in SdkHttpFullRequest where constructing with a query string consisting of a single \"=\" would throw an ArrayIndexOutOfBoundsException.

or something that is more specific ?

}
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)
Comment on lines +408 to 409
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map(s -> s.length == 0 ? new String[] {""} : s)
.map(s -> s.length == 1 ? new String[] { s[0], null } : s)
.map(s -> {
if (s.length == 0) {
return new String[] {""};
}
return s.length == 1 ? new String[] {s[0], null} : s;
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean return new String[] {"", null}; in line 410? cause otherwise it will fail on original line 410

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, yup

.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,13 @@ public void uriParams() throws URISyntaxException {
entry("decoded&Part", Arrays.asList("equals=val")));
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Test
@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");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for completeness can we add test in SdkHttpRequestResponseTest since this tests the Public API

    @Test
    public void testSdkHttpRequestWithEmptyEqualQueryParameterName() {
        final String expected = "http://example.com?=";
        URI myUri = URI.create(expected);
        SdkHttpRequest actual = SdkHttpRequest.builder().method(SdkHttpMethod.POST).uri(myUri).build();
        assertThat(actual.getUri()).hasToString(expected);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail because our current implementation will eliminate "=" when there are no query values. I added a test that the expected result string is "http://example.com?"

public void uriParamsWithSingleEqualQuery() throws URISyntaxException {
URI uri = URI.create("http://example.com?=");
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
assertThat(uriParams).contains(entry("", Arrays.asList((String)null)));
}

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