Closed
Description
Alexander Hawley opened SPR-10306 and commented
When using the Spring request mapping annotation (org.springframework.web.bind.annotation.RequestMapping
), the value
attribute does not map an encoded URI correctly. Some encoded reserved characters are excluded.
For example, the slash character /
, encoded as %2f
, is excluded.
Results as follows.
List of strings which contain reserved characters:
List<String> paths = Arrays.asList(
"foo%boo"
,"foo/boo"
,"foo?boo"
,"foo=boo"
,"foo&boo"
,"foo#boo"
,"foo$boo"
,"foo+boo"
,"foo,boo"
,"foo:boo"
,"foo;boo"
,"foo@boo"
);
Controller action to receive requests:
@RequestMapping(value = "/encoded/{value}", method = RequestMethod.GET)
public @ResponseBody String encoded_show() {
return "encoded_show";
}
Results in the URIs & responses (when requested):
path: "foo%boo"
uri: "/encoded/foo%25boo"
controller_action: "encoded_show"
path: "foo/boo"
uri: "/encoded/foo%2Fboo"
controller_action: (404 Not Found)
path: "foo?boo"
uri: "/encoded/foo%3Fboo"
controller_action: "encoded_show"
path: "foo=boo"
uri: "/encoded/foo%3Dboo"
controller_action: "encoded_show"
path: "foo&boo"
uri: "/encoded/foo%26boo"
controller_action: "encoded_show"
path: "foo#boo"
uri: "/encoded/foo%23boo"
controller_action: "encoded_show"
path: "foo$boo"
uri: "/encoded/foo%24boo"
controller_action: "encoded_show"
path: "foo+boo"
uri: "/encoded/foo%2Bboo"
controller_action: "encoded_show"
path: "foo,boo"
uri: "/encoded/foo%2Cboo"
controller_action: "encoded_show"
path: "foo:boo"
uri: "/encoded/foo%3Aboo"
controller_action: "encoded_show"
path: "foo;boo"
uri: "/encoded/foo%3Bboo"
controller_action: "encoded_show"
path: "foo@boo"
uri: "/encoded/foo%40boo"
controller_action: "encoded_show"
In order to catch the request for foo/boo
(encoded as foo%2Fboo
), an additional controller action must be used with wildcard instead of path parameter:
@RequestMapping(value = "/encoded/**", method = RequestMethod.GET)
public @ResponseBody String encoded_any() {
return "encoded_any";
}
Any ideas?
Thanks.
-AH
Affects: 3.1 GA
Issue Links:
- Spring URI template class does not encode a URI correctly [SPR-10305] #14939 Spring URI template class does not encode a URI correctly ("is duplicated by")
- spring:url tag does not correctly encode forward slash / in path variable. Should be calling encodePathSegment [SPR-11401] #16028 spring:url tag does not correctly encode forward slash / in path variable. Should be calling encodePathSegment
- Spring tag library does not encode a URI correctly [SPR-10303] #14937 Spring tag library does not encode a URI correctly
1 votes, 3 watchers