Skip to content

Encoded forward slashes in URL cause wrong links #226

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
meyertee opened this issue Aug 11, 2014 · 7 comments
Open

Encoded forward slashes in URL cause wrong links #226

meyertee opened this issue Aug 11, 2014 · 7 comments
Labels
in: core Core parts of the project type: bug

Comments

@meyertee
Copy link

For example when calling this URL: http://localhost:8080/things/%2Fsome%2Fthing, then this is produced in the controller method:

@RequestMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<ThingResource> get(@PathVariable("id") String id) {
    Link link = linkTo(ThingController.class).slash(id).withSelfRel();
    System.out.println(link.getHref());
    //...
}

It prints http://localhost:8080/things/some/thing/things/some/thing where it should produce http://localhost:8080/things/%2Fsome%2Fthing.

There are two problems:

  1. It takes the decoded path-variable as the base-path of the request mapping. This only happens when there is a leading %2F. If the leading character is another one the mapping works
  2. It appends the id unencoded where it should be encoded (I guess)

I'm well aware that slashes in path variables are problematic, but they do work in Spring MVC now, see https://jira.spring.io/browse/SPR-7919 & https://jira.spring.io/browse/SPR-11101

The problem could be in ServletUriComponentsBuilder.fromServletMapping(HttpServletRequest) where a UrlPathHelper is instantiated which defaults to urlDecode = true. The fix for having encoded slashes in Spring MVC is to set urlDecode = false, I guess that's related. Maybe that could be made configurable?

@SandyJone
Copy link

the same question

@davidfarina
Copy link

I'd be happy to have this fixed. Facing the same problem right now

@gregturn
Copy link
Contributor

gregturn commented Dec 6, 2018

Duplicates #593.

@izeye
Copy link
Contributor

izeye commented Jan 3, 2019

@gregturn You seem to intend to close this as a duplicate of #593.

@gregturn
Copy link
Contributor

gregturn commented Jan 3, 2019

At this state I just wanted to link them.

@izeye
Copy link
Contributor

izeye commented Jan 3, 2019

@gregturn Ah, sorry for the noise 😅

@odrotbohm
Copy link
Member

We just added a fix for #593. Would you folks mind giving the snapshots a spin?

@odrotbohm odrotbohm added in: core Core parts of the project type: bug labels Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: bug
Projects
None yet
Development

No branches or pull requests

6 participants