AntPathPatternMatcher hardcoded "/" separator in variables matching and comparator #33085
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related: #26264
When AntPathMatcher is constructed with a path separator other than default character "/", the functionality of extraction of URI template variables doesn’t work properly. If the matcher is specified with a non-default character, and a part of URI variable template includes default separator as a variable name, the variable name key mapping leads to exceptions or unexpected results. This is because the regex for URI template variables is hard-coded with "/", which is not considered as a part of variable key, although it can be placed if the matcher has a non-default path separator. To fix this, I updated it to pass a path separator to that regex.
Currently, for example, the matcher with non-default path separator seems to be leveraged on WebSocketConfiguration, in default, to map a "."-separated resource, which is a part of URI segment. Thus, for instance, if the path separator is specified as ".", extracting “price.stock.aaa“ with the template "price.stock.{ticker/symbol}" leads to IllegalStateException.
NOTE: A hard-coded variable pattern is still remaining. It seemed to be indirectly used in PathMatcher#compare implementation, but I’m not sure if this erroneous code causes some bug behaviors or not and is tracked by the team. And for isolation reasons, I would like to exclude it from the scope of code fix in this PR.
spring-framework/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
Line 81 in b134f25