Skip to content
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

RequestMappingHandlerMapping matches uri with percent encoded characters [SPR-12274] #16879

spring-projects-issues opened this issue Sep 30, 2014 · 2 comments
in: core in: web status: declined


Copy link

@spring-projects-issues spring-projects-issues commented Sep 30, 2014

Michal opened SPR-12274 and commented

As described in provided question on stackoverflow. In spring mvc application i found out that org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping matches some requests to controllers instead of returning no match. Mentioned requests contain percent encoded characters in front of path part of uri.
Example requests: - is decoded to /^Fapi/1.0/client/abc but matches /api/1.0/client/abc - is decoded to /^Kapi/1.0/client/abc but matches /api/1.0/client/abc

Example logs for first request :
DEBUG RequestMappingHandlerMapping - Looking up handler method for path /^Fapi/1.0/client/abc
TRACE RequestMappingHandlerMapping - Found 1 matching mapping(s) for [/^Fapi/1.0/client/abc] : [{[/api/1.0/client/{clientId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}]

Not every percent encoded character applies here, for some of them behavior is correct and application returns http 404: - returns 404, is decoded to /�api/1.0/client/abc and does not match /api/1.0/client/abc

I am not having issues with encoding neither in application nor in tomcat container. In web.xml file in application i have CharacterEncodingFilter filter with UTF-8 encoding. Application runs on Tomcat 7 with http and ajp connectors configured with URIEncoding="UTF-8".
I guess that all percent encoded characters are decoded correctly and problem is somewhere in RequestMappingHandlerMapping matching mechanism.

Affects: 3.2.8

Reference URL:

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 30, 2014

Rossen Stoyanchev commented

AntPathMatcher tokenizes the path and by default trims all segments. This behavior can be controlled. You'll need to configure the RequestMappingHandlerMapping with an AntPathMatcher with setTrimTokens(false).

Also note that in the 4.0 line (and higher) the MVC Java config and namespace have dedicated support for plugging in a custom PathMatcher. For 3.2.x follow the instructions in the reference for advanced MVC config changes.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 30, 2014

Michal commented

Thank you for your time. I have checked your solution and i confirm that setting trimTokens to false on AntPathMatcher solves described problem.

@spring-projects-issues spring-projects-issues added type: bug status: declined in: core in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core in: web status: declined
None yet

No branches or pull requests

2 participants