File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
main/java/org/springframework/hateoas/server/core
test/java/org/springframework/hateoas/server/core Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 2525import java .util .Collection ;
2626import java .util .Collections ;
2727import java .util .List ;
28- import java .util .regex .Pattern ;
2928import java .util .stream .Collectors ;
3029
3130import org .springframework .http .HttpMethod ;
3231import org .springframework .http .MediaType ;
3332import org .springframework .lang .Nullable ;
3433import org .springframework .util .Assert ;
34+ import org .springframework .util .StringUtils ;
3535import org .springframework .web .bind .annotation .RequestMethod ;
3636
3737/**
4545@ Deprecated
4646public class AnnotationMappingDiscoverer implements MappingDiscoverer {
4747
48- private static final Pattern MULTIPLE_SLASHES = Pattern .compile ("/{2,}" );
49-
5048 private final Class <? extends Annotation > annotationType ;
5149 private final String mappingAttributeName ;
5250
@@ -213,14 +211,18 @@ private static String cleanup(String mapping) {
213211
214212 String part = parts [i ];
215213
214+ if (!StringUtils .hasText (part )) {
215+ continue ;
216+ }
217+
216218 if (i != 0 ) {
217219 result .append ("/" );
218220 }
219221
220222 result .append (part .contains (":" ) ? cleanupPart (part ) : part );
221223 }
222224
223- return MULTIPLE_SLASHES . matcher ( result . toString ()). replaceAll ("/" );
225+ return ( mapping . endsWith ( "/" ) ? result . append ("/" ) : result ). toString ( );
224226 }
225227
226228 private static String cleanupPart (String part ) {
Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ void extractsMultipleRegularExpressionVariablesCorrectly() throws Exception {
179179 assertThat (discoverer .getMapping (method )).isEqualTo ("/type/spring-web/{symbolicName}-{version}{extension}" );
180180 }
181181
182+ @ Test // #1468
183+ void keepsTrailingSlash () throws Exception {
184+
185+ Method method = TrailingSlashes .class .getMethod ("trailingSlash" );
186+
187+ assertThat (discoverer .getMapping (method )).isEqualTo ("/api/myentities/" );
188+ }
189+
182190 @ RequestMapping ("/type" )
183191 interface MyController {
184192
@@ -267,4 +275,12 @@ interface MultipleMappingsController {
267275 @ RequestMapping ({ "/method" , "/methodAlias" })
268276 void method ();
269277 }
278+
279+ // #1468
280+
281+ interface TrailingSlashes {
282+
283+ @ RequestMapping ("/api/myentities/" )
284+ Object trailingSlash ();
285+ }
270286}
You can’t perform that action at this time.
0 commit comments