Skip to content

ControllerLinkBuilder link expansion leads to multiple url-encoding of parameters #559

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

Open
rainerfrey opened this issue Mar 21, 2017 · 4 comments

Comments

@rainerfrey
Copy link

rainerfrey commented Mar 21, 2017

When building a link with methodOn, and supplying values for some parameters but not all, a link template with variables for the remaining parameters is created, while the supplied values are already expanded. When expanding the resulting template, the initially supplied values are url-encoded again, leading to invalid URLs. This affects explicitly calling expand() of course, but also the pagination links of the PagedResourcesAssembler from Spring Data. Here is some code example:

    @GetMapping("/")
    public Resource test(
            @RequestParam(name = "date1", required = false) @DateTimeFormat(iso = DATE_TIME) Date date1,
            @RequestParam(name = "date2", required = false) @DateTimeFormat(iso = DATE_TIME) Date date2) {
        Link template = linkTo(methodOn(TestController.class).test(date1, null)).withRel("template");
        Link expanded = linkTo(methodOn(TestController.class).test(date1, null)).withRel("expanded").expand();
        return new Resource("", template, expanded);
    }

This leads to following response:

{
    "_links": {
        "expanded": {
            "href": "http://localhost:8080/?date1=2017-03-21T19:20:20.000%25252B0000"
        },
        "template": {
            "href": "http://localhost:8080/?date1=2017-03-21T19:20:20.000%2B0000{&date2}",
            "templated": true
        }
    },
    "content": ""
}

As you see, the + in the date has been encoded correctly in the template, but the %-sign has been encoded again in the expanded link, even twice as shown by the additional 25.

I have a runnable example with a test case in this repository

@ripperr
Copy link

ripperr commented Aug 1, 2017

Same issue here.

@ndzeller
Copy link

Experiencing problems with this issue as well.

@tmbell
Copy link

tmbell commented Feb 9, 2018

Approaching a year on this bug. Anybody looking into it? or found a viable workaround?

@jeffreycrump
Copy link

This bug makes the ControllerLinkBuilder pretty much useless for creating non-templated links. Any idea on the progress of this PR?

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

5 participants