@@ -694,34 +694,25 @@ void extractUriTemplateVarsRegexCapturingGroups() {
694694 }
695695
696696 @ Test
697- void combine () {
697+ void combineEmptyPatternsShouldReturnEmpty () {
698698 TestPathCombiner pathMatcher = new TestPathCombiner ();
699699 assertThat (pathMatcher .combine ("" , "" )).isEmpty ();
700+ }
701+
702+ @ Test
703+ void combineWithEmptyPatternShouldReturnPattern () {
704+ TestPathCombiner pathMatcher = new TestPathCombiner ();
700705 assertThat (pathMatcher .combine ("/hotels" , "" )).isEqualTo ("/hotels" );
701706 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 ();
704712 assertThat (pathMatcher .combine ("/hotels" , "/booking" )).isEqualTo ("/hotels/booking" );
705713 assertThat (pathMatcher .combine ("/hotels" , "booking" )).isEqualTo ("/hotels/booking" );
706714 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" );
723715 // SPR-10062
724- assertThat (pathMatcher .combine ("/{foo:.*[^0-9].*}" , "/edit/" )).isEqualTo ("/{foo:.*[^0-9].*}/edit/" );
725716 assertThat (pathMatcher .combine ("/1.0" , "/foo/test" )).isEqualTo ("/1.0/foo/test" );
726717 // SPR-10554
727718 // SPR-12975
@@ -730,14 +721,56 @@ void combine() {
730721 assertThat (pathMatcher .combine ("/hotel/" , "/booking" )).isEqualTo ("/hotel/booking" );
731722 assertThat (pathMatcher .combine ("" , "/hotel" )).isEqualTo ("/hotel" );
732723 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" );
734726 }
735727
736728 @ Test
737- void combineWithTwoFileExtensionPatterns () {
729+ void combineStaticWithMatchingShouldConcatenate () {
738730 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.*" );
741774 }
742775
743776 @ Test
@@ -1053,6 +1086,12 @@ public String combine(String string1, String string2) {
10531086 return pattern1 .combine (pattern2 ).getPatternString ();
10541087 }
10551088
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+
10561095 }
10571096
10581097}
0 commit comments