spring-projects / spring-projects/spring-hateoas
ControllerLinkBuilder does not correctly decode special chars
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
Unfortunately, slashes and special characters don't get encoded if you build a link via ControllerLinkBuilder.
Paste into ControllerLinkBuilderFactoryUnitTest
@Test
public void linksToMethodWithPathVariableContainingSpecialChars() {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable(":/+:) = :)")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/something/%3A%2F%20%3A)%20%3D%20%3A)/foo"));
}
Expected: a string ending with "/something/%3A%2F%20%3A)%20%3D%20%3A)/foo"
but: was "http://localhost/something/:/+:)%20=%20:)/foo"
@Test
public void linksToMethodContainingSpecialChars() {
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestParam(":/+:) = :)")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/something/foo?id=%3A%2F%20%3A)%20%3D%20%3A)"));
}
Expected: a string ending with "/something/foo?id=%3A%2F%20%3A)%20%3D%20%3A)"
but: was "http://localhost/something/foo?id=:/%2B:)%20%3D%20:)"
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 with ControllerLinkBuilderFactoryUnitTest and run the two provided link-building tests to reproduce the encoding failures. Trace the linkTo and methodOn entry points used there, then verify that path-variable and request-parameter values produce the expected encoded href endings shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100