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

Url are not escaped well in get parameters #374

Open
strokyl opened this issue Aug 10, 2015 · 0 comments
Open

Url are not escaped well in get parameters #374

strokyl opened this issue Aug 10, 2015 · 0 comments

Comments

@strokyl
Copy link

strokyl commented Aug 10, 2015

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()));
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

1 participant