Skip to content

Commit

Permalink
Improvement in AntPathMatcher.combine method
Browse files Browse the repository at this point in the history
Issues: SPR-7970
  • Loading branch information
rstoyanchev committed Apr 2, 2012
1 parent 4653dbe commit 9833a4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Expand Up @@ -299,7 +299,9 @@ else if (!StringUtils.hasText(pattern1)) {
else if (!StringUtils.hasText(pattern2)) {
return pattern1;
}
else if (!pattern1.contains("{") && match(pattern1, pattern2)) {
else if (!pattern1.equals(pattern2) && !pattern1.contains("{") && match(pattern1, pattern2)) {
// /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
return pattern2;
}
else if (pattern1.endsWith("/*")) {
Expand Down
Expand Up @@ -348,13 +348,13 @@ public void extractUriTemplateVariablesRegex() {
assertEquals("com.example", result.get("symbolicName"));
assertEquals("1.0.0", result.get("version"));
}

// SPR-7787

@Test
public void extractUriTemplateVarsRegexQualifiers() {
Map<String, String> result = pathMatcher.extractUriTemplateVariables(
"{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar",
"{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar",
"com.example-sources-1.0.0.jar");
assertEquals("com.example", result.get("symbolicName"));
assertEquals("1.0.0", result.get("version"));
Expand All @@ -376,18 +376,18 @@ public void extractUriTemplateVarsRegexQualifiers() {
}

// SPR-8455

@Test
public void extractUriTemplateVarsRegexCapturingGroups() {
try {
pathMatcher.extractUriTemplateVariables("/web/{id:foo(bar)?}", "/web/foobar");
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertTrue("Expected helpful message on the use of capturing groups",
assertTrue("Expected helpful message on the use of capturing groups",
e.getMessage().contains("The number of capturing groups in the pattern"));
}
}

@Test
public void combine() {
assertEquals("", pathMatcher.combine(null, null));
Expand All @@ -410,7 +410,8 @@ public void combine() {
assertEquals("/*.html", pathMatcher.combine("/**", "/*.html"));
assertEquals("/*.html", pathMatcher.combine("/*", "/*.html"));
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar"));
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858
assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970
}

@Test
Expand Down

0 comments on commit 9833a4c

Please sign in to comment.