Skip to content

Commit

Permalink
Fix AntPathMatcher rule for combining with extensions
Browse files Browse the repository at this point in the history
Before this fix AntPathMatcher had a special rule for combining
patterns with wildcards and extensions as follows:

"/*.*"  + "/*.html" => "/*.html"

This change ensures this rule never applies if the first pattern
contains URI variables.

Issue: SPR-10062
  • Loading branch information
rstoyanchev committed Mar 1, 2013
1 parent 4cc30fe commit 33e723b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ else if (!StringUtils.hasText(pattern1)) {
else if (!StringUtils.hasText(pattern2)) {
return pattern1;
}
else if (!pattern1.equals(pattern2) && !pattern1.contains("{") && match(pattern1, pattern2)) {

boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
// /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
return pattern2;
Expand All @@ -344,7 +346,7 @@ else if (pattern1.endsWith("/**")) {
}
else {
int dotPos1 = pattern1.indexOf('.');
if (dotPos1 == -1) {
if (dotPos1 == -1 || pattern1ContainsUriVar) {
// simply concatenate the two patterns
if (pattern1.endsWith("/") || pattern2.startsWith("/")) {
return pattern1 + pattern2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ public void combine() {
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858
assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970
assertEquals("/{foo:.*[^0-9].*}/edit/", pathMatcher.combine("/{foo:.*[^0-9].*}", "/edit/")); // SPR-10062
}

@Test
Expand Down

0 comments on commit 33e723b

Please sign in to comment.