Skip to content
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

fix: UriTemplate reserved expansion does not escape reserved chars #1844

Merged
merged 1 commit into from May 5, 2023

Conversation

cHengstler
Copy link
Contributor

When using UriTemplate.expand with a reserved expansion "{+var}", a set of allowed characters must not be encoded. According to section of 3.2.3 Reserved Expansion: {+var}, unreserved and reserved character should not be escaped.

This fix adds the missing characters #[] that must not be percent encoded when using reserved expansion.

  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #1838

@cHengstler cHengstler requested a review from a team as a code owner April 19, 2023 09:48
@google-cla
Copy link

google-cla bot commented Apr 19, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@suztomo
Copy link
Member

suztomo commented May 4, 2023

Memo:

  1. Are the added characters (#[]) marked as the reserved set? Yes

      reserved       =  gen-delims / sub-delims
      gen-delims     =  ":" / "/" / "?" / "#" / "[" / "]" / "@"
    
  2. (Todo on me) Try out this change in java-storage before merge, and see any failures.
    => [No need to review] trying new reserved characters in http client java-storage#2005

@suztomo
Copy link
Member

suztomo commented May 4, 2023

@cHengstler Can you fix the lint failure?

[INFO] --- fmt-maven-plugin:2.9:check (default-cli) @ google-http-client ---
[INFO] Processed 100 files (1 non-complying).
[INFO] Processed 200 files (1 non-complying).
[INFO] Processed 216 files (2 non-complying).
Error:  Found 2 non-complying files, failing build
Error:  To fix formatting errors, run "mvn com.coveo:fmt-maven-plugin:format"
Error:  Non complying file: /home/runner/work/google-http-java-client/google-http-java-client/google-http-client/src/main/java/com/google/api/client/util/escape/PercentEscaper.java
Error:  Non complying file: /home/runner/work/google-http-java-client/google-http-java-client/google-http-client/src/test/java/com/google/api/client/http/UriTemplateTest.java

suztomo added a commit to suztomo/java-storage that referenced this pull request May 4, 2023
@cHengstler
Copy link
Contributor Author

Hi @suztomo,

thanks for reviewing, linting issues should be solved now.

assertEquals(
"Reserved expansion must not escape chars from unreserved set according to rfc6570#section-3.2.3",
unReservedSet,
UriTemplate.expand("{+var}", requestMap, false));
Copy link
Member

Choose a reason for hiding this comment

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

Memo: Python's uritemplate agrees:

>>> a="-._~"; a == URITemplate("{+var}").expand(var=a)
True
>>> a=":/?#[]@!$&'()*+,;="; a == URITemplate("{+var}").expand(var=a)
True

@suztomo suztomo added the automerge Merge the pull request once unit tests and other checks pass. label May 5, 2023
@suztomo suztomo changed the title UriTemplate reserved expansion does not escape reserved chars fix: UriTemplate reserved expansion does not escape reserved chars May 5, 2023
@suztomo
Copy link
Member

suztomo commented May 5, 2023

ci / lint passed.

@gcf-merge-on-green gcf-merge-on-green bot merged commit 91c46a9 into googleapis:main May 5, 2023
15 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UriTemplate reserved expansion should not escape reserved characters
2 participants