|
26 | 26 | import org.junit.Rule;
|
27 | 27 | import org.junit.Test;
|
28 | 28 | import org.junit.rules.ExpectedException;
|
| 29 | +import org.springframework.util.AntPathMatcher; |
29 | 30 |
|
30 | 31 | import static org.hamcrest.CoreMatchers.*;
|
31 | 32 | import static org.junit.Assert.*;
|
@@ -524,12 +525,40 @@ public void extractUriTemplateVariables_spr15264() {
|
524 | 525 | assertTrue(pp.matches("/abc/boo"));
|
525 | 526 | assertTrue(pp.matches("/a/boo"));
|
526 | 527 | assertFalse(pp.matches("//boo"));
|
| 528 | + |
| 529 | + pp = parse("/{foo}*"); |
| 530 | + assertTrue(pp.matches("/abc")); |
| 531 | + assertFalse(pp.matches("/")); |
527 | 532 |
|
528 | 533 | checkCapture("/{word:[a-z]*}", "/abc", "word", "abc");
|
529 | 534 | pp = parse("/{word:[a-z]*}");
|
530 | 535 | assertFalse(pp.matches("/1"));
|
531 | 536 | assertTrue(pp.matches("/a"));
|
532 | 537 | assertFalse(pp.matches("/"));
|
| 538 | + |
| 539 | + // Two captures mean we use a RegexPathElement |
| 540 | + pp = new PathPatternParser().parse("/{foo}{bar}"); |
| 541 | + assertTrue(pp.matches("/abcdef")); |
| 542 | + assertFalse(pp.matches("/")); |
| 543 | + assertFalse(pp.matches("//")); |
| 544 | + checkCapture("/{foo:[a-z][a-z]}{bar:[a-z]}", "/abc", "foo", "ab", "bar", "c"); |
| 545 | + |
| 546 | + // Only patterns not capturing variables cannot match against just / |
| 547 | + pp = new PathPatternParser().parse("/****"); |
| 548 | + assertTrue(pp.matches("/abcdef")); |
| 549 | + assertTrue(pp.matches("/")); |
| 550 | + assertTrue(pp.matches("//")); |
| 551 | + |
| 552 | + // Confirming AntPathMatcher behaviour: |
| 553 | + assertFalse(new AntPathMatcher().match("/{foo}", "/")); |
| 554 | + assertTrue(new AntPathMatcher().match("/{foo}", "/a")); |
| 555 | + assertTrue(new AntPathMatcher().match("/{foo}{bar}", "/a")); |
| 556 | + assertFalse(new AntPathMatcher().match("/{foo}*", "/")); |
| 557 | + assertTrue(new AntPathMatcher().match("/*", "/")); |
| 558 | + assertFalse(new AntPathMatcher().match("/*{foo}", "/")); |
| 559 | + Map<String, String> vars = new AntPathMatcher().extractUriTemplateVariables("/{foo}{bar}", "/a"); |
| 560 | + assertEquals("a",vars.get("foo")); |
| 561 | + assertEquals("",vars.get("bar")); |
533 | 562 | }
|
534 | 563 |
|
535 | 564 | @Test
|
|
0 commit comments