Reinstate removal of semicolon content
Commit 5b1165 was an attempt to leave semicolon content in the URL path while ignoring it for request mapping purposes. However, it becomes quite difficult to manage and semicolon content should not always be ignored (sometimes a semicolon is used as a separator of multiple items in a path segment, rather than for matrix variables). This change effectively reverts back to the original approach in 3.2 where a flag on AbstractHandlerMapping can be used to have semicolon content removed or kept. If kept, path segments with matrix variables must be represented with a path segment. The main difference is that by default it is removed everywhere including the MVC namespace and Java config. Issue: SPR-10427, SPR-10234
This commit is contained in:
@@ -157,6 +157,10 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
handlerMappingDef.getPropertyValues().add("order", 0);
|
||||
handlerMappingDef.getPropertyValues().add("contentNegotiationManager", contentNegotiationManager);
|
||||
String methodMappingName = parserContext.getReaderContext().registerWithGeneratedName(handlerMappingDef);
|
||||
if (element.hasAttribute("enableMatrixVariables")) {
|
||||
Boolean enableMatrixVariables = Boolean.valueOf(element.getAttribute("enableMatrixVariables"));
|
||||
handlerMappingDef.getPropertyValues().add("removeSemicolonContent", !enableMatrixVariables);
|
||||
}
|
||||
|
||||
RuntimeBeanReference conversionService = getConversionService(element, source, parserContext);
|
||||
RuntimeBeanReference validator = getValidator(element, source, parserContext);
|
||||
|
||||
@@ -128,7 +128,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
|
||||
/**
|
||||
* Set if ";" (semicolon) content should be stripped from the request URI.
|
||||
* <p>The default value is {@code false}.
|
||||
* <p>The default value is {@code true}.
|
||||
* @see org.springframework.web.util.UrlPathHelper#setRemoveSemicolonContent(boolean)
|
||||
*/
|
||||
public void setRemoveSemicolonContent(boolean removeSemicolonContent) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -37,7 +38,6 @@ import org.springframework.util.ReflectionUtils.MethodFilter;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.method.HandlerMethodSelector;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link HandlerMapping} implementations that define a
|
||||
@@ -62,12 +62,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
private final MultiValueMap<String, T> urlMap = new LinkedMultiValueMap<String, T>();
|
||||
|
||||
|
||||
public AbstractHandlerMethodMapping() {
|
||||
UrlPathHelper pathHelper = new UrlPathHelper();
|
||||
pathHelper.setRemoveSemicolonContent(false);
|
||||
setUrlPathHelper(pathHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to detect handler methods in beans in ancestor ApplicationContexts.
|
||||
* <p>Default is "false": Only beans in the current ApplicationContext are
|
||||
|
||||
@@ -42,13 +42,6 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
*/
|
||||
public final class PatternsRequestCondition extends AbstractRequestCondition<PatternsRequestCondition> {
|
||||
|
||||
private static UrlPathHelper pathHelperNoSemicolonContent;
|
||||
|
||||
static {
|
||||
pathHelperNoSemicolonContent = new UrlPathHelper();
|
||||
pathHelperNoSemicolonContent.setRemoveSemicolonContent(true);
|
||||
}
|
||||
|
||||
private final Set<String> patterns;
|
||||
|
||||
private final UrlPathHelper pathHelper;
|
||||
@@ -217,15 +210,10 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
}
|
||||
|
||||
String lookupPath = this.pathHelper.getLookupPathForRequest(request);
|
||||
String lookupPathNoSemicolonContent = (lookupPath.indexOf(';') != -1) ?
|
||||
pathHelperNoSemicolonContent.getLookupPathForRequest(request) : null;
|
||||
|
||||
List<String> matches = new ArrayList<String>();
|
||||
for (String pattern : patterns) {
|
||||
String match = getMatchingPattern(pattern, lookupPath);
|
||||
if (match == null && lookupPathNoSemicolonContent != null) {
|
||||
match = getMatchingPattern(pattern, lookupPathNoSemicolonContent);
|
||||
}
|
||||
if (match != null) {
|
||||
matches.add(match);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user