@@ -905,34 +905,25 @@ void extractUriTemplateVarsRegexCapturingGroups() {
905
905
}
906
906
907
907
@ Test
908
- void combine () {
908
+ void combineEmptyPatternsShouldReturnEmpty () {
909
909
TestPathCombiner pathMatcher = new TestPathCombiner ();
910
910
assertThat (pathMatcher .combine ("" , "" )).isEmpty ();
911
+ }
912
+
913
+ @ Test
914
+ void combineWithEmptyPatternShouldReturnPattern () {
915
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
911
916
assertThat (pathMatcher .combine ("/hotels" , "" )).isEqualTo ("/hotels" );
912
917
assertThat (pathMatcher .combine ("" , "/hotels" )).isEqualTo ("/hotels" );
913
- assertThat (pathMatcher .combine ("/hotels/*" , "booking" )).isEqualTo ("/hotels/booking" );
914
- assertThat (pathMatcher .combine ("/hotels/*" , "/booking" )).isEqualTo ("/hotels/booking" );
918
+ }
919
+
920
+ @ Test
921
+ void combineStaticPatternsShouldConcatenate () {
922
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
915
923
assertThat (pathMatcher .combine ("/hotels" , "/booking" )).isEqualTo ("/hotels/booking" );
916
924
assertThat (pathMatcher .combine ("/hotels" , "booking" )).isEqualTo ("/hotels/booking" );
917
925
assertThat (pathMatcher .combine ("/hotels/" , "booking" )).isEqualTo ("/hotels/booking" );
918
- assertThat (pathMatcher .combine ("/hotels/*" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
919
- assertThat (pathMatcher .combine ("/hotels" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
920
- assertThat (pathMatcher .combine ("/hotels" , "{hotel}.*" )).isEqualTo ("/hotels/{hotel}.*" );
921
- assertThat (pathMatcher .combine ("/hotels/*/booking" , "{booking}" )).isEqualTo ("/hotels/*/booking/{booking}" );
922
- assertThat (pathMatcher .combine ("/*.html" , "/hotel.html" )).isEqualTo ("/hotel.html" );
923
- assertThat (pathMatcher .combine ("/*.html" , "/hotel" )).isEqualTo ("/hotel.html" );
924
- assertThat (pathMatcher .combine ("/*.html" , "/hotel.*" )).isEqualTo ("/hotel.html" );
925
- // TODO this seems rather bogus, should we eagerly show an error?
926
- assertThat (pathMatcher .combine ("/a/b/c/*.html" , "/d/e/f/hotel.*" )).isEqualTo ("/d/e/f/hotel.html" );
927
- assertThat (pathMatcher .combine ("/**" , "/*.html" )).isEqualTo ("/*.html" );
928
- assertThat (pathMatcher .combine ("/*" , "/*.html" )).isEqualTo ("/*.html" );
929
- assertThat (pathMatcher .combine ("/*.*" , "/*.html" )).isEqualTo ("/*.html" );
930
- // SPR-8858
931
- assertThat (pathMatcher .combine ("/{foo}" , "/bar" )).isEqualTo ("/{foo}/bar" );
932
- // SPR-7970
933
- assertThat (pathMatcher .combine ("/user" , "/user" )).isEqualTo ("/user/user" );
934
926
// SPR-10062
935
- assertThat (pathMatcher .combine ("/{foo:.*[^0-9].*}" , "/edit/" )).isEqualTo ("/{foo:.*[^0-9].*}/edit/" );
936
927
assertThat (pathMatcher .combine ("/1.0" , "/foo/test" )).isEqualTo ("/1.0/foo/test" );
937
928
// SPR-10554
938
929
// SPR-12975
@@ -941,14 +932,56 @@ void combine() {
941
932
assertThat (pathMatcher .combine ("/hotel/" , "/booking" )).isEqualTo ("/hotel/booking" );
942
933
assertThat (pathMatcher .combine ("" , "/hotel" )).isEqualTo ("/hotel" );
943
934
assertThat (pathMatcher .combine ("/hotel" , "" )).isEqualTo ("/hotel" );
944
- // TODO Do we need special handling when patterns contain multiple dots?
935
+ // SPR-7970
936
+ assertThat (pathMatcher .combine ("/user" , "/user" )).isEqualTo ("/user/user" );
945
937
}
946
938
947
939
@ Test
948
- void combineWithTwoFileExtensionPatterns () {
940
+ void combineStaticWithMatchingShouldConcatenate () {
949
941
TestPathCombiner pathMatcher = new TestPathCombiner ();
950
- assertThatIllegalArgumentException ().isThrownBy (() ->
951
- pathMatcher .combine ("/*.html" , "/*.txt" ));
942
+ assertThat (pathMatcher .combine ("/hotels" , "*" )).isEqualTo ("/hotels/*" );
943
+ assertThat (pathMatcher .combine ("/hotels" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
944
+ assertThat (pathMatcher .combine ("/hotels" , "{hotel}.*" )).isEqualTo ("/hotels/{hotel}.*" );
945
+ }
946
+
947
+ @ Test
948
+ void combineMatchingWithStaticShouldMergeWhenWildcardMatch () {
949
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
950
+ assertThat (pathMatcher .combine ("/hotels/*" , "booking" )).isEqualTo ("/hotels/booking" );
951
+ assertThat (pathMatcher .combine ("/hotels/*" , "/booking" )).isEqualTo ("/hotels/booking" );
952
+ assertThat (pathMatcher .combine ("/hotels/**" , "/booking/rooms" )).isEqualTo ("/hotels/booking/rooms" );
953
+ assertThat (pathMatcher .combine ("/*.html" , "/hotel.html" )).isEqualTo ("/hotel.html" );
954
+ assertThat (pathMatcher .combine ("/*.html" , "/hotel" )).isEqualTo ("/hotel.html" );
955
+ // gh-34986
956
+ assertThat (pathMatcher .combine ("/*" , "/foo/bar" )).isEqualTo ("/foo/bar" );
957
+ assertThat (pathMatcher .combine ("/*" , "foo/bar" )).isEqualTo ("/foo/bar" );
958
+ }
959
+
960
+ @ Test
961
+ void combineMatchingWithStaticShouldConcatenateWhenNoWildcardMatch () {
962
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
963
+ // SPR-10062
964
+ assertThat (pathMatcher .combine ("/{foo:.*[^0-9].*}" , "/edit/" )).isEqualTo ("/{foo:.*[^0-9].*}/edit/" );
965
+ // SPR-8858
966
+ assertThat (pathMatcher .combine ("/{foo}" , "/bar" )).isEqualTo ("/{foo}/bar" );
967
+ }
968
+
969
+ @ Test
970
+ void combineMatchingPatternsShouldMergeWhenMatch () {
971
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
972
+ assertThat (pathMatcher .combine ("/hotels/*/booking" , "{booking}" )).isEqualTo ("/hotels/*/booking/{booking}" );
973
+ assertThat (pathMatcher .combine ("/hotels/*" , "{hotel}" )).isEqualTo ("/hotels/{hotel}" );
974
+ assertThat (pathMatcher .combine ("/*.html" , "/hotel.*" )).isEqualTo ("/hotel.html" );
975
+ assertThat (pathMatcher .combine ("/**" , "/*.html" )).isEqualTo ("/*.html" );
976
+ assertThat (pathMatcher .combine ("/*" , "/*.html" )).isEqualTo ("/*.html" );
977
+ assertThat (pathMatcher .combine ("/*.*" , "/*.html" )).isEqualTo ("/*.html" );
978
+ }
979
+
980
+ @ Test
981
+ void combineMatchingPatternsShouldFailWhenNoMatch () {
982
+ TestPathCombiner pathMatcher = new TestPathCombiner ();
983
+ pathMatcher .combineFails ("/*.html" , "/*.txt" );
984
+ pathMatcher .combineFails ("/a/b/c/*.html" , "/d/e/f/hotel.*" );
952
985
}
953
986
954
987
@ Test
@@ -1268,6 +1301,12 @@ public String combine(String string1, String string2) {
1268
1301
return pattern1 .combine (pattern2 ).getPatternString ();
1269
1302
}
1270
1303
1304
+ public void combineFails (String string1 , String string2 ) {
1305
+ PathPattern pattern1 = pp .parse (string1 );
1306
+ PathPattern pattern2 = pp .parse (string2 );
1307
+ assertThatIllegalArgumentException ().isThrownBy (() -> pattern1 .combine (pattern2 ));
1308
+ }
1309
+
1271
1310
}
1272
1311
1273
1312
}
0 commit comments