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
{{ message }}
Repository navigation
Reject "/path/**/other" patterns in PathPatternParser #24952
Thanks for raising this, it seems we need to improve that case in our implementation and in the reference docs.
First, I believe this is by design (see the first comment in #19112); if I remember correctly, not supporting "**" segments in the middle of patterns was done on purpose, for several reasons:
this does not perform well, since it requires backtracking
it's been often the source of misunderstanding and complex matches which lead to strange matches or even security issues in particular applications
PathPattern does support ** at the end of the pattern only (see PathPattern Javadoc) - the same way it supports the new "/path/{*captureTheRest}" syntax (but with additional capturing).
I'll turn this issue into an enhancement with two goals:
Ensure that "/path/**/other" patterns are rejected with PatternParseException
changed the title [-]Behavior difference between PathPatternParser(WebFlux) vs AntPathMatcher(MVC)[/-][+]Reject "/path/**/other" patterns in PathPatternParser (WebFlux)[/+]on Apr 21, 2020
I see a recent ticket #24945 to align MVC towards using PathPatternParser. Won't this be a breaking change ?
This won't be a breaking change since we'll support both AntPathMatcher and PathPatternParser infrastructures for Spring MVC, leaving the current one as the default. This just gives an extra choice for developers interested in optimal path matching performance (we're getting quite a few requests about that).
I wonder why there are different strategies used for WebFlux and MVC. Would have been better if the change remained consistent across both.
WebFlux was a completely new effort and we took that opportunity to revisit parts we wanted to improve. Aligning both MVC and WebFlux right away in Spring Framework 5.0 wouldn't have been a wise choice since at that point we didn't have much experience/feedback on running WebFlux applications in production.
As for adding that feature to PathPatternParser, I don't think we should do that for the reasons listed above. Even if WebFlux applications are less popular than MVC apps, I believe it's the first time we're getting an issue about this since 5.0 is out (in 2017).
If both AntPathMatcher and PathPatternParser options are available for MVC I was wondering if there will be an option available to the developer to choose one or the other infrastructure ?
@ranarula Yes, we’ll provide a configuration option in the usual places in Spring Framework and we’ll probably make it a configuration property in Spring Boot.
Activity
bclozel commentedon Apr 21, 2020
Thanks for raising this, it seems we need to improve that case in our implementation and in the reference docs.
First, I believe this is by design (see the first comment in #19112); if I remember correctly, not supporting
"**"segments in the middle of patterns was done on purpose, for several reasons:PathPatterndoes support**at the end of the pattern only (seePathPatternJavadoc) - the same way it supports the new"/path/{*captureTheRest}"syntax (but with additional capturing).I'll turn this issue into an enhancement with two goals:
"/path/**/other"patterns are rejected withPatternParseException[-]Behavior difference between PathPatternParser(WebFlux) vs AntPathMatcher(MVC)[/-][+]Reject "/path/**/other" patterns in PathPatternParser (WebFlux)[/+]bclozel commentedon Apr 21, 2020
Note: this issue can be reproduced with a simple test:
ranarula commentedon Apr 21, 2020
@bclozel - I see a recent ticket #24945 to align MVC towards using PathPatternParser. Won't this be a breaking change ?
I wonder why there are different strategies used for WebFlux and MVC. Would have been better if the change remained consistent across both.
bclozel commentedon Apr 21, 2020
This won't be a breaking change since we'll support both
AntPathMatcherandPathPatternParserinfrastructures for Spring MVC, leaving the current one as the default. This just gives an extra choice for developers interested in optimal path matching performance (we're getting quite a few requests about that).WebFlux was a completely new effort and we took that opportunity to revisit parts we wanted to improve. Aligning both MVC and WebFlux right away in Spring Framework 5.0 wouldn't have been a wise choice since at that point we didn't have much experience/feedback on running WebFlux applications in production.
As for adding that feature to
PathPatternParser, I don't think we should do that for the reasons listed above. Even if WebFlux applications are less popular than MVC apps, I believe it's the first time we're getting an issue about this since 5.0 is out (in 2017).ranarula commentedon Apr 21, 2020
Thanks @bclozel for the explanation. Make sense.
If both
AntPathMatcherandPathPatternParseroptions are available for MVC I was wondering if there will be an option available to the developer to choose one or the other infrastructure ?bclozel commentedon Apr 21, 2020
@ranarula Yes, we’ll provide a configuration option in the usual places in Spring Framework and we’ll probably make it a configuration property in Spring Boot.
rstoyanchev commentedon Apr 22, 2020
This is a good idea. The error could suggest re-writing as
"/path/*/other"and that should be an easy correction.Also the
PathPatternJavadoc could be made more explicit. Currently it says only:5 remaining items
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
refactor(tests): replace AntPathMatcher as path matching strategy ins…
Reject "/path/**/other" patterns in PathPatternParser