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

Mandatory parameters are escaped twice when using Traverson API #498

Open
ydecoux opened this issue Sep 28, 2016 · 2 comments
Open

Mandatory parameters are escaped twice when using Traverson API #498

ydecoux opened this issue Sep 28, 2016 · 2 comments

Comments

@ydecoux
Copy link

ydecoux commented Sep 28, 2016

Related to #337 when a rel contains a mandatory param that needs to be escaped, it will be escaped twice.
In the following example, the rel to follow is /springagram/item/{itemId} where itemId is '123#456'

Resource<?> itemResource = traverson.//
    follow(rel("item").withParameters(Collections.singletonMap("itemId", "123#456"))).//
    toObject(Resource.class);

The final url will be resolved as /springagram/item/123%2523456 instead of /springagram/item/123%23456

The problem is inside org.springframework.hateoas.UriTemplate#expand(java.util.Map<java.lang.String,? extends java.lang.Object>)
When creating a new org.springframework.web.util.UriTemplate, the baseUri is escaped a first time (# is escaped as %23).
Then, when executing builder.build().toUri() the whole url is escaped a second time (hence %23 is escaped as %2523).

The thing is that is works well if you only have optional param inside your rel but as soon as you have one mandatiry param that needs to be escaped, then it will be escaped twice.

ydecoux added a commit to ydecoux/spring-hateoas that referenced this issue Sep 28, 2016
@msparer
Copy link

msparer commented Feb 8, 2019

Also, due to the same code portion, non-ascii optional parameters don't get encoded at all. E.g. to use your itemId as optional param:

/springagram/item/{?itemId}

final Link link = new Link("/springagram/item/{?itemId}");
System.out.println(link.expand(Collections.singletonMap("itemId", "MØ")).getHref());

prints /springagram/item/?itemId=MØ instead of the expected /springagram/item/?itemId=M%C3%98.

As a reminder, non-ascii characters in URLs must be encoded, this doesn't necessarily apply to URIs.

@ydecoux I know this issue is more than two years old, but could you please create a PR, maybe the project leads can have a quick look into it and make your fix part of the next release. Fingers crossed.

@msparer
Copy link

msparer commented Feb 11, 2019

@gregturn any chance to get this in?

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

No branches or pull requests

2 participants