Enable use of parsed patterns by default in Spring MVC

Closes gh-28607
This commit is contained in:
rstoyanchev
2022-06-28 20:37:14 +01:00
parent 8a9b082d8a
commit 92cf1e13e8
16 changed files with 234 additions and 146 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ import org.springframework.web.util.pattern.PathPatternParser;
*/
public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource {
private static PathMatcher defaultPathMatcher = new AntPathMatcher();
private static final PathMatcher defaultPathMatcher = new AntPathMatcher();
private final PathPatternParser patternParser;
@@ -157,7 +157,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
* pattern matching with {@link PathMatcher} or with parsed {@link PathPattern}s.
* <p>In Spring MVC, either a resolved String lookupPath or a parsed
* {@code RequestPath} is always available within {@code DispatcherServlet}
* processing. However in a Servlet {@code Filter} such as {@code CorsFilter}
* processing. However, in a Servlet {@code Filter} such as {@code CorsFilter}
* that may or may not be the case.
* <p>By default this is set to {@code true} in which case lazy lookupPath
* initialization is allowed. Set this to {@code false} when an

View File

@@ -252,6 +252,9 @@ public abstract class ServletRequestPathUtils {
if (UrlPathHelper.servlet4Present) {
String servletPathPrefix = Servlet4Delegate.getServletPathPrefix(request);
if (StringUtils.hasText(servletPathPrefix)) {
if (servletPathPrefix.endsWith("/")) {
servletPathPrefix = servletPathPrefix.substring(0, servletPathPrefix.length() - 1);
}
return new ServletRequestPath(requestUri, request.getContextPath(), servletPathPrefix);
}
}
@@ -272,8 +275,7 @@ public abstract class ServletRequestPathUtils {
if (mapping == null) {
mapping = request.getHttpServletMapping();
}
MappingMatch match = mapping.getMappingMatch();
if (!ObjectUtils.nullSafeEquals(match, MappingMatch.PATH)) {
if (!ObjectUtils.nullSafeEquals(mapping.getMappingMatch(), MappingMatch.PATH)) {
return null;
}
String servletPath = (String) request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE);