Description
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:
- 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 - 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?