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 2424import java .util .Collection ;
2525import java .util .Collections ;
2626import java .util .List ;
27- import java .util .regex .Pattern ;
2827
2928import org .springframework .http .HttpMethod ;
3029import org .springframework .lang .Nullable ;
3130import org .springframework .util .Assert ;
31+ import org .springframework .util .StringUtils ;
3232import org .springframework .web .bind .annotation .RequestMethod ;
3333
3434/**
4242@ Deprecated
4343public class AnnotationMappingDiscoverer implements MappingDiscoverer {
4444
45- private static final Pattern MULTIPLE_SLASHES = Pattern .compile ("/{2,}" );
46-
4745 private final Class <? extends Annotation > annotationType ;
4846 private final String mappingAttributeName ;
4947
@@ -195,14 +193,18 @@ private static String cleanup(String mapping) {
195193
196194 String part = parts [i ];
197195
196+ if (!StringUtils .hasText (part )) {
197+ continue ;
198+ }
199+
198200 if (i != 0 ) {
199201 result .append ("/" );
200202 }
201203
202204 result .append (part .contains (":" ) ? cleanupPart (part ) : part );
203205 }
204206
205- return MULTIPLE_SLASHES . matcher ( result . toString ()). replaceAll ("/" );
207+ return ( mapping . endsWith ( "/" ) ? result . append ("/" ) : result ). toString ( );
206208 }
207209
208210 private static String cleanupPart (String part ) {
Original file line number Diff line number Diff line change @@ -168,6 +168,14 @@ void extractsMultipleRegularExpressionVariablesCorrectly() throws Exception {
168168 assertThat (discoverer .getMapping (method )).isEqualTo ("/type/spring-web/{symbolicName}-{version}{extension}" );
169169 }
170170
171+ @ Test // #1469
172+ void keepsTrailingSlash () throws Exception {
173+
174+ Method method = TrailingSlashes .class .getMethod ("trailingSlash" );
175+
176+ assertThat (discoverer .getMapping (method )).isEqualTo ("/api/myentities/" );
177+ }
178+
171179 @ RequestMapping ("/type" )
172180 interface MyController {
173181
@@ -253,4 +261,12 @@ interface MultipleMappingsController {
253261 @ RequestMapping ({ "/method" , "/methodAlias" })
254262 void method ();
255263 }
264+
265+ // #1469
266+
267+ interface TrailingSlashes {
268+
269+ @ RequestMapping ("/api/myentities/" )
270+ Object trailingSlash ();
271+ }
256272}
You can’t perform that action at this time.
0 commit comments