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
RequestMapping: case insensitive path matching [SPR-13286] #17876
Comments
Yi EungJun commented I'm trying to fix this myself. At the first glance, this issue can be solved by making AntPathMatcher matches patterns in case-insensitive manner as follows: diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
index 3132b1c..5bee271 100644
--- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
+++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
@@ -583,7 +583,7 @@ public class AntPathMatcher implements PathMatcher {
end = m.end();
}
patternBuilder.append(quote(pattern, end, pattern.length()));
- this.pattern = Pattern.compile(patternBuilder.toString());
+ this.pattern = Pattern.compile(patternBuilder.toString(), Pattern.CASE_INSENSITIVE);
}
private String quote(String s, int start, int end) { But I am afraid that it causes a lot of side-effects because RequestMapping is not the only client which uses AntPathMatcher. I guess the side effects may be avoided by adding a flag for case-insensitive matching to AntPathmathcer and RequestMapping. Is there anything more should be considered? |
Juergen Hoeller commented I've introduced a public Juergen |
Yi EungJun commented It sounds great! I think it would make sense to me. Is it possible to configure that AntPathMatcher matches in case-insensitive manner only for a specific controller? And can I try the your new AntPathMatcher? |
Juergen Hoeller commented I've turned this around into a I'm afraid the only way to customize the Juergen |
Yi EungJun commented I tested it and it works very well for me! Thanks very much, Juergen. Here is my configuration: @Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
AntPathMatcher matcher = new AntPathMatcher();
matcher.setCaseSensitive(false);
configurer.setPathMatcher(matcher);
}
} |
Yi EungJun opened SPR-13286 and commented
I want
@RequestMapping
annotations to match paths in case-insensitive manner so that@RequestMapping("/path/to/{name}")
matches not only/path/to/me
but also/path/To/me
,/PATH/to/me
, and so on.There is a known workaround to do that as follows:
But it makes the values of URI template variables lowercase. I want to keep the case information.
Referenced from: commits 291550a
The text was updated successfully, but these errors were encountered: