spring-projects / spring-projects/spring-hateoas
Url are not escaped well in get parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
When I reverse a method by specifying a get parameter with an URL, the URL is not escaped correctly.
For example, if I do:
resource.add(linkTo(methodOn(controllerClass).getCommentOfArticle(resource.getBaseUrl()+"&toto=2")).withRel("commentsOnSameNews"));
Where getCommentOfArticle is the following method inside a @RestController:
@RequestMapping(method = RequestMethod.GET)
public List<CommentResource> getCommentOfArticle(
@RequestParam("baseUrl") String baseUrl) {
return commentResourceAssembler.toResources(commentService
.getComments(baseUrl, pageUrl));
}
It will generate the following link:
http://localhost:8080/myproject/resources/comment?baseUrl=http://localhost:8080/cmstoolsWeb&toto=2
Instead of
http://localhost:8080/myproject/resources/comment?baseUrl=http%3A%2F%2Flocalhost%3A8080%2Ftest.jsp%26toto%3D2
This is verry anoying because if I escape it before, then Spring hateaos reescape my %.
So I have to this and it's really horrible :
String linkWithPageHolder = linkTo(
methodOn(controllerClass).getCommentOfArticle(
"baseUrlPlaceHolder",)).withRel(
"useless").getHref();
linkWithPageHolder = linkWithPageHolder.replaceFirst(
"baseUrlPlaceHolder",
EncodingUtil.encodeURIComponent(resource.getBaseUrl()));
String linkWithPageHolder = linkTo(
methodOn(controllerClass).getCommentOfArticle(
"baseUrlPlaceHolder", "pageUrlPlaceHolder")).withRel(
"useless").getHref();
linkWithPageHolder = linkWithPageHolder.replaceFirst(
"baseUrlPlaceHolder",
EncodingUtil.encodeURIComponent(resource.getBaseUrl()));
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 by reproducing the URL generated by linkTo(methodOn(...)) with the controller and get-parameter example in the issue. Trace how the URL argument is encoded, and consider the issue done when embedded URL characters are escaped correctly without double-encoding already escaped values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100