Ignore path parameters in request mappings

Before this change the presence of path params (e.g. "/foo;q=1/bar")
expected the request mapping to contain a URI variable in the place of
semicolon content (e.g. either "/{foo}/bar" or "/{foo};{fooParams}").

The change ensures path params are ignored in @RequestMapping patterns
so that "/foo/bar" matches to "/foo;q=1/bar" as well as
"/foo;q=1;p=2/bar".

Along with this change, the RequestMappingHandlerMapping no longer
defaults to having semicolon content removed from the URL, which means
@MatrixVariable is supported by default without the need for any
further configuration.

Issue: SPR-10234
This commit is contained in:
Rossen Stoyanchev
2013-02-15 11:31:32 -05:00
parent eda53ec1d8
commit 5b1165b102
8 changed files with 42 additions and 22 deletions

View File

@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.web.util.UrlPathHelper;
/**
* @author Rossen Stoyanchev
@@ -185,6 +186,16 @@ public class PatternsRequestConditionTests {
assertNull(match);
}
@Test
public void matchIgnorePathParams() {
UrlPathHelper pathHelper = new UrlPathHelper();
pathHelper.setRemoveSemicolonContent(false);
PatternsRequestCondition condition = new PatternsRequestCondition(new String[] {"/foo/bar"}, pathHelper, null, true, true);
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo;q=1/bar;s=1"));
assertNotNull(match);
}
@Test
public void compareEqualPatterns() {
PatternsRequestCondition c1 = new PatternsRequestCondition("/foo*");

View File

@@ -90,7 +90,6 @@ public class RequestMappingInfoHandlerMappingTests {
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
this.handlerMapping.registerHandler(testController);
this.handlerMapping.setRemoveSemicolonContent(false);
}
@Test