You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm curious why AntPathMatcher matches a path with a trailing slash differently if the pattern contains a ** pattern. See the following example:
AntPathMatcher matcher = new AntPathMatcher();
matcher.match("/en", "/en/") == false // does not match
matcher.match("/*/en", "/en/foo/") == false // does not match
matcher.match("/**/foo", "/en/foo/") == true // does match
Could someone enlighten me why AntPathMatcher behaves this way?
The text was updated successfully, but these errors were encountered:
aomader
changed the title
AntPathMatcher differently matches path with trailing slash if '**' is present in the pattern
AntPathMatcher matches path with trailing slash differently if '**' is present in the pattern
Oct 1, 2021
// does not match because the pattern doesn't have a trailing slash and the path has one
matcher.match("/en", "/en/")
// does not match because the pattern ends with "/en" and the path ends with "/foo/"
matcher.match("/*/en", "/en/foo/")
// this is problematic
matcher.match("/**/foo", "/en/foo/") == true // does match
I've tested the following combinations and it looks like there is an inconsistency between * and ** when it comes to matching trailing slashes.
I've found a fix for this issue that doesn't break any test in our test suite, but AntPathMatcher has a long history of subtle behavior and lots of people relying on it.
Using ** within patterns and trailing slashes are very likely in web applications using AntPathMatcher. There is a trailing slash matching option in Spring MVC but applications might still rely on this behavior, so I'm not tempted to fix this in the 5.3.x branch.
On the other hand, I think that using AntPathMatcher as a matcher for request patterns in Spring MVC might be retired in Spring Framework 6.0. In the 6.0.x timeline we can consider several options for AntPathMatcher:
keeping it around as it is and fixing small issues like this one
reworking it to only target file patterns use cases (and not URL path patterns which is now PathPatternParser's job)
or retiring it completely
In any case, this needs to be discussed within the Spring Framework team.
Did you notice this issue in a Spring MVC application while debugging the problem, or AntPathMatcher for some other use case?
Regarding your first question, no, I cannot see a typo. The last case is obviously the problematic one and the reason I created this issue.
Exactly, I came across this "subtle behavior" when working with Spring MVC and Spring Security. The latter I find somewhat problematic with regards to "sublte behavior"...
rstoyanchev
added
in: web
Issues in web modules (web, webmvc, webflux, websocket)
in: core
Issues in core modules (aop, beans, core, context, expression)
labels
Nov 10, 2021
I'm curious why
AntPathMatcher
matches a path with a trailing slash differently if the pattern contains a**
pattern. See the following example:Could someone enlighten me why
AntPathMatcher
behaves this way?The text was updated successfully, but these errors were encountered: