spring-projects / spring-projects/spring-hateoas
Mandatory parameters are escaped twice when using Traverson API
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at org.springframework.hateoas.UriTemplate#expand(Map<String, ? extends Object>) and trace how the base URI is passed through org.springframework.web.util.UriTemplate and builder.build().toUri(). Reproduce the Traverson example with itemId "123#456". Done means the final URL contains 123%23456 rather than 123%2523456, while optional parameters continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100