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

When using ParsingPathMatcher in MVC user should not have to also explicitly set suffix matching [SPR-15303] #19868

Closed
spring-projects-issues opened this issue Mar 1, 2017 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 1, 2017

Dave Syer opened SPR-15303 and commented

With this request mapping:

@GetMapping("/something/{*path}")

This doesn't work:

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setPathMatcher(new ParsingPathMatcher());
}
2017-03-01 17:43:51.763 ERROR 3503 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.util.patterns.PatternParseException: No more pattern data allowed after {*...} pattern element] with root cause

org.springframework.web.util.patterns.PatternParseException: No more pattern data allowed after {*...} pattern element
	at org.springframework.web.util.patterns.InternalPathPatternParser.parse(InternalPathPatternParser.java:157) ~[spring-web-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.util.patterns.PathPatternParser.parse(PathPatternParser.java:68) ~[spring-web-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.util.ParsingPathMatcher.getPathPattern(ParsingPathMatcher.java:115) ~[spring-web-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.util.ParsingPathMatcher.match(ParsingPathMatcher.java:50) ~[spring-web-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getMatchingPattern(PatternsRequestCondition.java:253) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getMatchingPatterns(PatternsRequestCondition.java:230) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getMatchingCondition(PatternsRequestCondition.java:211) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.servlet.mvc.method.RequestMappingInfo.getMatchingCondition(RequestMappingInfo.java:220) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
	at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getMatchingMapping(RequestMappingInfoHandlerMapping.java:94) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
...

The problem is that the request matcher tries to match "/something/{path}." (suffix matching) or "/something/{*path}/" (trailing slash).

This does work:

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setPathMatcher(new ParsingPathMatcher());
    configurer.setUseSuffixPatternMatch(false);
    configurer.setUseTrailingSlashMatch(false);
}

but why should the user have to know about how to do that? If the user does have to know this, then the error message is completely cryptic, and maybe we can come up with a better one.


Affects: 5.0 M5

Issue Links:

Referenced from: commits 0557404

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Since changing the configuration behind the user's back or silently ignoring the exceptions were not good options, I've added a configuration check in the PathMatchConfigurer to throw an exception explaining the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants