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

allow single "=" as query #5823

merged 9 commits into from
Jan 31, 2025

Conversation

Fred1155
Copy link
Contributor

@Fred1155 Fred1155 commented Jan 24, 2025

Motivation and Context

There is a issue on SdkHttpFullRequest throws exception when constructing with query string is a single "=". The "=" query is valid according to RFC spec. We should treat it as a valid query string. This is because when spliting query strings, "=" will be splited to an empty list, resulting in array out of bound.
Fixed the bug "ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0" when "=" as the query string

Modifications

  1. filter out the length 0 list when splitQueryString

Testing

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@Fred1155 Fred1155 requested a review from a team as a code owner January 24, 2025 17:57
@joviegas
Copy link
Contributor

  • Can we please mention some details about this bug fix , how is SDK user impacted by this or in what circumstances will this issue be seen ?
  • How did we discover this bug ?
  • Do we need change log ?

public void uriParamsWithSingleEqualQuery() throws URISyntaxException {
URI uri = URI.create("http://example.com?=");
Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
assertThat(uriParams).isEmpty();
Copy link
Contributor

@joviegas joviegas Jan 24, 2025

Choose a reason for hiding this comment

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

Consider

    @Test
    public void uriParamsWithEmptyKeyAndValue() throws URISyntaxException {     //Interested
        URI uri = URI.create("http://example.com?=myValue");
        Map<String, List<String>> uriParams = SdkHttpUtils.uriParams(uri);
        System.out.println("uriParams " +uriParams);

    }

For http://example.com?=myValue the uriParams looks like
uriParams {=[myValue]}

If you see here the Key in the Map is empty .

Now based on this for "http://example.com?=" we should have empty key with empty list or null as below
uriParams {=[]}or uriParams {=null} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline, {=null} conforms with current implementation

@@ -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?"

"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 ?

@Fred1155 Fred1155 added this pull request to the merge queue Jan 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 30, 2025
@Fred1155 Fred1155 added this pull request to the merge queue Jan 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 30, 2025
@Fred1155 Fred1155 added this pull request to the merge queue Jan 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 30, 2025
Copy link

@Fred1155 Fred1155 added this pull request to the merge queue Jan 30, 2025
Comment on lines +408 to 409
.map(s -> s.length == 0 ? new String[] {""} : s)
.map(s -> s.length == 1 ? new String[] { s[0], null } : s)
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

github-merge-queue bot pushed a commit that referenced this pull request Jan 31, 2025
* allow single = as query

* unit test added

* changelog added

* changed the behavior

* minor change

* more test cases added
Merged via the queue into master with commit e7d281c Jan 31, 2025
17 checks passed
ghetelgb pushed a commit to ghetelgb/aws-sdk-java-v2 that referenced this pull request Feb 7, 2025
* allow single = as query

* unit test added

* changelog added

* changed the behavior

* minor change

* more test cases added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants