Skip to content

UriTemplate redundantly percent encodes literal part #1127

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

Closed
bodewig opened this issue Nov 27, 2019 · 4 comments
Closed

UriTemplate redundantly percent encodes literal part #1127

bodewig opened this issue Nov 27, 2019 · 4 comments
Assignees
Labels
in: core Core parts of the project type: bug
Milestone

Comments

@bodewig
Copy link

bodewig commented Nov 27, 2019

When using UriTemplate with a literal part using reserved characters the part is percent encoded twice. For example

new UriTemplate("https://example.org/foo and bar/{baz}").expand("xyzzy")

yields https://example.org/foo%2520and%2520bar/xyzzy rather than the expected https://example.org/foo%20and%20bar/xyzzy. I think this happens because UriTemplate.expand first constructs and expands a Spring Framework UriTemplate from the literal part (which adds percent encoding), builds a UriComponentsBuilder from the result and later calls build with no arguments on this UriComponentsBuilder which adds another layer of percent encoding. I think it would be possible to percent encode all variable values beforehand and then invoke build(false) instead, but I haven't checked all code paths.

Note that when using UriTemplate with a properly percent-encoded literal part to begin with, things become even worse because of spring-projects/spring-framework#24094.

new UriTemplate("https://example.org/foo%20and%20bar/{baz}").expand("xyzzy")

yields https://example.org/foo%252520and%252520bar/xyzzy.

odrotbohm added a commit that referenced this issue Nov 28, 2019
We now directly use UriComponentsBuilder in UriTemplate.expand(…) to avoid potential double encoding in the base URI.
odrotbohm added a commit that referenced this issue Nov 28, 2019
We now directly use UriComponentsBuilder in UriTemplate.expand(…) to avoid potential double encoding in the base URI.
@odrotbohm
Copy link
Member

I followed @rstoyanchev's advice from spring-projects/spring-framework#24094 and avoid Spring's UriTemplate entirely. Also backported to 1.0.x via #1130.

@odrotbohm odrotbohm added this to the 1.1.0.M1 milestone Nov 28, 2019
@odrotbohm odrotbohm self-assigned this Nov 28, 2019
@odrotbohm odrotbohm added in: core Core parts of the project type: bug labels Nov 28, 2019
@gregturn
Copy link
Contributor

gregturn commented Nov 28, 2019

Possibly related to #593. If so, and if resolved, there’s a great test case we’ll be a me to add there to avoid regressions.

@odrotbohm
Copy link
Member

I revisited encoding related tickets and am just polishing up a fix for #593.

@bodewig
Copy link
Author

bodewig commented Nov 28, 2019

Great, many thanks @odrotbohm !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: bug
Projects
None yet
Development

No branches or pull requests

3 participants