Skip to content

Spring request mapping annotation does not map an encoded URI correctly [SPR-10306] #14940

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

1 votes, 3 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions