@@ -905,34 +905,25 @@ void extractUriTemplateVarsRegexCapturingGroups() {
905905 }
906906
907907 @ Test
908- void combine () {
908+ void combineEmptyPatternsShouldReturnEmpty () {
909909 TestPathCombiner pathMatcher = new TestPathCombiner ();
910910 assertThat (pathMatcher .combine ("" , "" )).isEmpty ();
911+ }
912+
913+ @ Test
914+ void combineWithEmptyPatternShouldReturnPattern () {
915+ TestPathCombiner pathMatcher = new TestPathCombiner ();
911916 assertThat (pathMatcher .combine ("/hotels" , "" )).isEqualTo ("/hotels" );
912917 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 ();
915923 assertThat (pathMatcher .combine ("/hotels" , "/booking" )).isEqualTo ("/hotels/booking" );
916924 assertThat (pathMatcher .combine ("/hotels" , "booking" )).isEqualTo ("/hotels/booking" );
917925 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" );
934926 // SPR-10062
935- assertThat (pathMatcher .combine ("/{foo:.*[^0-9].*}" , "/edit/" )).isEqualTo ("/{foo:.*[^0-9].*}/edit/" );
936927 assertThat (pathMatcher .combine ("/1.0" , "/foo/test" )).isEqualTo ("/1.0/foo/test" );
937928 // SPR-10554
938929 // SPR-12975
@@ -941,14 +932,56 @@ void combine() {
941932 assertThat (pathMatcher .combine ("/hotel/" , "/booking" )).isEqualTo ("/hotel/booking" );
942933 assertThat (pathMatcher .combine ("" , "/hotel" )).isEqualTo ("/hotel" );
943934 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" );
945937 }
946938
947939 @ Test
948- void combineWithTwoFileExtensionPatterns () {
940+ void combineStaticWithMatchingShouldConcatenate () {
949941 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.*" );
952985 }
953986
954987 @ Test
@@ -1268,6 +1301,12 @@ public String combine(String string1, String string2) {
12681301 return pattern1 .combine (pattern2 ).getPatternString ();
12691302 }
12701303
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+
12711310 }
12721311
12731312}
0 commit comments