Browse Source

SPR-8858 Fix in AntPathMatcher.combine(..)

Currently the combine method consolidates "/*" and "/hotel" 
into "/hotel". However if the first pattern contains URI template 
variables, the consolidation seems wrong. The fix is to prevent
the consolidation if the first pattern contains "{".
pull/7/head
Rossen Stoyanchev 13 years ago
parent
commit
b5bcfa0ae3
  1. 2
      org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java
  2. 3
      org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java
  3. 9
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java

2
org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java

@ -299,7 +299,7 @@ public class AntPathMatcher implements PathMatcher {
else if (!StringUtils.hasText(pattern2)) { else if (!StringUtils.hasText(pattern2)) {
return pattern1; return pattern1;
} }
else if (match(pattern1, pattern2)) { else if (!pattern1.contains("{") && match(pattern1, pattern2)) {
return pattern2; return pattern2;
} }
else if (pattern1.endsWith("/*")) { else if (pattern1.endsWith("/*")) {

3
org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java

@ -407,7 +407,10 @@ public class AntPathMatcherTests {
assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.html")); assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.html"));
assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel")); assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel"));
assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.*")); assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.*"));
assertEquals("/*.html", pathMatcher.combine("/**", "/*.html"));
assertEquals("/*.html", pathMatcher.combine("/*", "/*.html"));
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html")); assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar"));
} }
@Test @Test

9
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java

@ -148,10 +148,11 @@ public class ServletAnnotationMappingUtilsTests {
@Test @Test
public void checkHeadersKeyValueNoMatchWithNegation() { public void checkHeadersKeyValueNoMatchWithNegation() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.addHeader("header1", "value1"); request.addHeader("Accept-Encoding", "gzip");
String[] headers = new String[]{"header1!=value1"}; String[] headers1 = new String[]{"Accept-Encoding!=gzip"};
boolean result = ServletAnnotationMappingUtils.checkHeaders(headers, request); String[] headers2 = new String[]{"Accept-Encoding=gzip"};
assertFalse("Invalid request method result", result); assertFalse(ServletAnnotationMappingUtils.checkHeaders(headers1, request));
assertTrue(ServletAnnotationMappingUtils.checkHeaders(headers2, request));
} }
@Test @Test

Loading…
Cancel
Save