|
1 | 1 | /* |
2 | | - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -418,8 +418,8 @@ public void combine() { |
418 | 418 | assertEquals("/*.html", pathMatcher.combine("/**", "/*.html")); |
419 | 419 | assertEquals("/*.html", pathMatcher.combine("/*", "/*.html")); |
420 | 420 | assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html")); |
421 | | - assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858 |
422 | | - assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970 |
| 421 | + assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858 |
| 422 | + assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970 |
423 | 423 | assertEquals("/{foo:.*[^0-9].*}/edit/", pathMatcher.combine("/{foo:.*[^0-9].*}", "/edit/")); // SPR-10062 |
424 | 424 | assertEquals("/1.0/foo/test", pathMatcher.combine("/1.0", "/foo/test")); // SPR-10554 |
425 | 425 | assertEquals("/hotel", pathMatcher.combine("/", "/hotel")); // SPR-12975 |
@@ -454,8 +454,8 @@ public void patternComparator() { |
454 | 454 |
|
455 | 455 | // SPR-10550 |
456 | 456 | assertEquals(-1, comparator.compare("/hotels/{hotel}/bookings/{booking}/cutomers/{customer}", "/**")); |
457 | | - assertEquals(1, comparator.compare("/**","/hotels/{hotel}/bookings/{booking}/cutomers/{customer}")); |
458 | | - assertEquals(0, comparator.compare("/**","/**")); |
| 457 | + assertEquals(1, comparator.compare("/**", "/hotels/{hotel}/bookings/{booking}/cutomers/{customer}")); |
| 458 | + assertEquals(0, comparator.compare("/**", "/**")); |
459 | 459 |
|
460 | 460 | assertEquals(-1, comparator.compare("/hotels/{hotel}", "/hotels/*")); |
461 | 461 | assertEquals(1, comparator.compare("/hotels/*", "/hotels/{hotel}")); |
@@ -618,12 +618,44 @@ public void cachePatternsSetToTrue() { |
618 | 618 | assertTrue(pathMatcher.stringMatcherCache.size() > 20); |
619 | 619 |
|
620 | 620 | for (int i = 0; i < 65536; i++) { |
621 | | - pathMatcher.match("test" + i, "test"); |
| 621 | + pathMatcher.match("test" + i, "test" + i); |
622 | 622 | } |
623 | 623 | // Cache keeps being alive due to the explicit cache setting |
624 | 624 | assertTrue(pathMatcher.stringMatcherCache.size() > 65536); |
625 | 625 | } |
626 | 626 |
|
| 627 | + @Test |
| 628 | + public void preventCreatingStringMatchersIfPathDoesNotStartsWithPatternPrefix() { |
| 629 | + pathMatcher.setCachePatterns(true); |
| 630 | + assertEquals(0, pathMatcher.stringMatcherCache.size()); |
| 631 | + |
| 632 | + pathMatcher.match("test?", "test"); |
| 633 | + assertEquals(1, pathMatcher.stringMatcherCache.size()); |
| 634 | + |
| 635 | + pathMatcher.match("test?", "best"); |
| 636 | + pathMatcher.match("test/*", "view/test.jpg"); |
| 637 | + pathMatcher.match("test/**/test.jpg", "view/test.jpg"); |
| 638 | + pathMatcher.match("test/{name}.jpg", "view/test.jpg"); |
| 639 | + assertEquals(1, pathMatcher.stringMatcherCache.size()); |
| 640 | + } |
| 641 | + |
| 642 | + @Test |
| 643 | + public void creatingStringMatchersIfPatternPrefixCannotDetermineIfPathMatch() { |
| 644 | + pathMatcher.setCachePatterns(true); |
| 645 | + assertEquals(0, pathMatcher.stringMatcherCache.size()); |
| 646 | + |
| 647 | + pathMatcher.match("test", "testian"); |
| 648 | + pathMatcher.match("test?", "testFf"); |
| 649 | + pathMatcher.match("test/*", "test/dir/name.jpg"); |
| 650 | + pathMatcher.match("test/{name}.jpg", "test/lorem.jpg"); |
| 651 | + pathMatcher.match("bla/**/test.jpg", "bla/test.jpg"); |
| 652 | + pathMatcher.match("**/{name}.jpg", "test/lorem.jpg"); |
| 653 | + pathMatcher.match("/**/{name}.jpg", "/test/lorem.jpg"); |
| 654 | + pathMatcher.match("/*/dir/{name}.jpg", "/*/dir/lorem.jpg"); |
| 655 | + |
| 656 | + assertEquals(7, pathMatcher.stringMatcherCache.size()); |
| 657 | + } |
| 658 | + |
627 | 659 | @Test |
628 | 660 | public void cachePatternsSetToFalse() { |
629 | 661 | pathMatcher.setCachePatterns(false); |
|
0 commit comments