@@ -694,34 +694,25 @@ void extractUriTemplateVarsRegexCapturingGroups() {
694
694
}
695
695
696
696
@ Test
697
- void combine () {
697
+ void combineEmptyPatternsShouldReturnEmpty () {
698
698
TestPathCombiner pathMatcher = new TestPathCombiner ();
699
699
assertThat (pathMatcher .combine ("" , "" )).isEmpty ();
700
+ }
701
+
702
+ @ Test
703
+ void combineWithEmptyPatternShouldReturnPattern () {
704
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
700
705
assertThat (pathMatcher .combine ("/hotels" , "" )).isEqualTo ("/hotels" );
701
706
assertThat (pathMatcher .combine ("" , "/hotels" )).isEqualTo ("/hotels" );
702
- assertThat (pathMatcher .combine ("/hotels/*" , "booking" )).isEqualTo ("/hotels/booking" );
703
- assertThat (pathMatcher .combine ("/hotels/*" , "/booking" )).isEqualTo ("/hotels/booking" );
707
+ }
708
+
709
+ @ Test
710
+ void combineStaticPatternsShouldConcatenate () {
711
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
704
712
assertThat (pathMatcher .combine ("/hotels" , "/booking" )).isEqualTo ("/hotels/booking" );
705
713
assertThat (pathMatcher .combine ("/hotels" , "booking" )).isEqualTo ("/hotels/booking" );
706
714
assertThat (pathMatcher .combine ("/hotels/" , "booking" )).isEqualTo ("/hotels/booking" );
707
- assertThat (pathMatcher .combine ("/hotels/*" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
708
- assertThat (pathMatcher .combine ("/hotels" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
709
- assertThat (pathMatcher .combine ("/hotels" , "{hotel}.*" )).isEqualTo ("/hotels/{hotel}.*" );
710
- assertThat (pathMatcher .combine ("/hotels/*/booking" , "{booking}" )).isEqualTo ("/hotels/*/booking/{booking}" );
711
- assertThat (pathMatcher .combine ("/*.html" , "/hotel.html" )).isEqualTo ("/hotel.html" );
712
- assertThat (pathMatcher .combine ("/*.html" , "/hotel" )).isEqualTo ("/hotel.html" );
713
- assertThat (pathMatcher .combine ("/*.html" , "/hotel.*" )).isEqualTo ("/hotel.html" );
714
- // TODO this seems rather bogus, should we eagerly show an error?
715
- assertThat (pathMatcher .combine ("/a/b/c/*.html" , "/d/e/f/hotel.*" )).isEqualTo ("/d/e/f/hotel.html" );
716
- assertThat (pathMatcher .combine ("/**" , "/*.html" )).isEqualTo ("/*.html" );
717
- assertThat (pathMatcher .combine ("/*" , "/*.html" )).isEqualTo ("/*.html" );
718
- assertThat (pathMatcher .combine ("/*.*" , "/*.html" )).isEqualTo ("/*.html" );
719
- // SPR-8858
720
- assertThat (pathMatcher .combine ("/{foo}" , "/bar" )).isEqualTo ("/{foo}/bar" );
721
- // SPR-7970
722
- assertThat (pathMatcher .combine ("/user" , "/user" )).isEqualTo ("/user/user" );
723
715
// SPR-10062
724
- assertThat (pathMatcher .combine ("/{foo:.*[^0-9].*}" , "/edit/" )).isEqualTo ("/{foo:.*[^0-9].*}/edit/" );
725
716
assertThat (pathMatcher .combine ("/1.0" , "/foo/test" )).isEqualTo ("/1.0/foo/test" );
726
717
// SPR-10554
727
718
// SPR-12975
@@ -730,14 +721,56 @@ void combine() {
730
721
assertThat (pathMatcher .combine ("/hotel/" , "/booking" )).isEqualTo ("/hotel/booking" );
731
722
assertThat (pathMatcher .combine ("" , "/hotel" )).isEqualTo ("/hotel" );
732
723
assertThat (pathMatcher .combine ("/hotel" , "" )).isEqualTo ("/hotel" );
733
- // TODO Do we need special handling when patterns contain multiple dots?
724
+ // SPR-7970
725
+ assertThat (pathMatcher .combine ("/user" , "/user" )).isEqualTo ("/user/user" );
734
726
}
735
727
736
728
@ Test
737
- void combineWithTwoFileExtensionPatterns () {
729
+ void combineStaticWithMatchingShouldConcatenate () {
738
730
TestPathCombiner pathMatcher = new TestPathCombiner ();
739
- assertThatIllegalArgumentException ().isThrownBy (() ->
740
- pathMatcher .combine ("/*.html" , "/*.txt" ));
731
+ assertThat (pathMatcher .combine ("/hotels" , "*" )).isEqualTo ("/hotels/*" );
732
+ assertThat (pathMatcher .combine ("/hotels" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
733
+ assertThat (pathMatcher .combine ("/hotels" , "{hotel}.*" )).isEqualTo ("/hotels/{hotel}.*" );
734
+ }
735
+
736
+ @ Test
737
+ void combineMatchingWithStaticShouldMergeWhenWildcardMatch () {
738
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
739
+ assertThat (pathMatcher .combine ("/hotels/*" , "booking" )).isEqualTo ("/hotels/booking" );
740
+ assertThat (pathMatcher .combine ("/hotels/*" , "/booking" )).isEqualTo ("/hotels/booking" );
741
+ assertThat (pathMatcher .combine ("/hotels/**" , "/booking/rooms" )).isEqualTo ("/hotels/booking/rooms" );
742
+ assertThat (pathMatcher .combine ("/*.html" , "/hotel.html" )).isEqualTo ("/hotel.html" );
743
+ assertThat (pathMatcher .combine ("/*.html" , "/hotel" )).isEqualTo ("/hotel.html" );
744
+ // gh-34986
745
+ assertThat (pathMatcher .combine ("/*" , "/foo/bar" )).isEqualTo ("/foo/bar" );
746
+ assertThat (pathMatcher .combine ("/*" , "foo/bar" )).isEqualTo ("/foo/bar" );
747
+ }
748
+
749
+ @ Test
750
+ void combineMatchingWithStaticShouldConcatenateWhenNoWildcardMatch () {
751
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
752
+ // SPR-10062
753
+ assertThat (pathMatcher .combine ("/{foo:.*[^0-9].*}" , "/edit/" )).isEqualTo ("/{foo:.*[^0-9].*}/edit/" );
754
+ // SPR-8858
755
+ assertThat (pathMatcher .combine ("/{foo}" , "/bar" )).isEqualTo ("/{foo}/bar" );
756
+ }
757
+
758
+ @ Test
759
+ void combineMatchingPatternsShouldMergeWhenMatch () {
760
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
761
+ assertThat (pathMatcher .combine ("/hotels/*/booking" , "{booking}" )).isEqualTo ("/hotels/*/booking/{booking}" );
762
+ assertThat (pathMatcher .combine ("/hotels/*" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
763
+ assertThat (pathMatcher .combine ("/*.html" , "/hotel.*" )).isEqualTo ("/hotel.html" );
764
+ assertThat (pathMatcher .combine ("/**" , "/*.html" )).isEqualTo ("/*.html" );
765
+ assertThat (pathMatcher .combine ("/*" , "/*.html" )).isEqualTo ("/*.html" );
766
+ assertThat (pathMatcher .combine ("/*.*" , "/*.html" )).isEqualTo ("/*.html" );
767
+ }
768
+
769
+ @ Test
770
+ void combineMatchingPatternsShouldFailWhenNoMatch () {
771
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
772
+ pathMatcher .combineFails ("/*.html" , "/*.txt" );
773
+ pathMatcher .combineFails ("/a/b/c/*.html" , "/d/e/f/hotel.*" );
741
774
}
742
775
743
776
@ Test
@@ -1053,6 +1086,12 @@ public String combine(String string1, String string2) {
1053
1086
return pattern1 .combine (pattern2 ).getPatternString ();
1054
1087
}
1055
1088
1089
+ public void combineFails (String string1 , String string2 ) {
1090
+ PathPattern pattern1 = pp .parse (string1 );
1091
+ PathPattern pattern2 = pp .parse (string2 );
1092
+ assertThatIllegalArgumentException ().isThrownBy (() -> pattern1 .combine (pattern2 ));
1093
+ }
1094
+
1056
1095
}
1057
1096
1058
1097
}
0 commit comments