Skip to content

Commit 9833a4c

Browse files
committed
Improvement in AntPathMatcher.combine method
Issues: SPR-7970
1 parent 4653dbe commit 9833a4c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ else if (!StringUtils.hasText(pattern1)) {
299299
else if (!StringUtils.hasText(pattern2)) {
300300
return pattern1;
301301
}
302-
else if (!pattern1.contains("{") && match(pattern1, pattern2)) {
302+
else if (!pattern1.equals(pattern2) && !pattern1.contains("{") && match(pattern1, pattern2)) {
303+
// /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
304+
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
303305
return pattern2;
304306
}
305307
else if (pattern1.endsWith("/*")) {

spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ public void extractUriTemplateVariablesRegex() {
348348
assertEquals("com.example", result.get("symbolicName"));
349349
assertEquals("1.0.0", result.get("version"));
350350
}
351-
351+
352352
// SPR-7787
353-
353+
354354
@Test
355355
public void extractUriTemplateVarsRegexQualifiers() {
356356
Map<String, String> result = pathMatcher.extractUriTemplateVariables(
357-
"{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar",
357+
"{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar",
358358
"com.example-sources-1.0.0.jar");
359359
assertEquals("com.example", result.get("symbolicName"));
360360
assertEquals("1.0.0", result.get("version"));
@@ -376,18 +376,18 @@ public void extractUriTemplateVarsRegexQualifiers() {
376376
}
377377

378378
// SPR-8455
379-
379+
380380
@Test
381381
public void extractUriTemplateVarsRegexCapturingGroups() {
382382
try {
383383
pathMatcher.extractUriTemplateVariables("/web/{id:foo(bar)?}", "/web/foobar");
384384
fail("Expected exception");
385385
} catch (IllegalArgumentException e) {
386-
assertTrue("Expected helpful message on the use of capturing groups",
386+
assertTrue("Expected helpful message on the use of capturing groups",
387387
e.getMessage().contains("The number of capturing groups in the pattern"));
388388
}
389389
}
390-
390+
391391
@Test
392392
public void combine() {
393393
assertEquals("", pathMatcher.combine(null, null));
@@ -410,7 +410,8 @@ public void combine() {
410410
assertEquals("/*.html", pathMatcher.combine("/**", "/*.html"));
411411
assertEquals("/*.html", pathMatcher.combine("/*", "/*.html"));
412412
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));
413-
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar"));
413+
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858
414+
assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970
414415
}
415416

416417
@Test

0 commit comments

Comments
 (0)