File tree 2 files changed +22
-4
lines changed
main/java/org/springframework/hateoas/server/core
test/java/org/springframework/hateoas/server/core
2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 25
25
import java .util .Collection ;
26
26
import java .util .Collections ;
27
27
import java .util .List ;
28
- import java .util .regex .Pattern ;
29
28
import java .util .stream .Collectors ;
30
29
31
30
import org .springframework .http .HttpMethod ;
32
31
import org .springframework .http .MediaType ;
33
32
import org .springframework .lang .Nullable ;
34
33
import org .springframework .util .Assert ;
34
+ import org .springframework .util .StringUtils ;
35
35
import org .springframework .web .bind .annotation .RequestMethod ;
36
36
37
37
/**
45
45
@ Deprecated
46
46
public class AnnotationMappingDiscoverer implements MappingDiscoverer {
47
47
48
- private static final Pattern MULTIPLE_SLASHES = Pattern .compile ("/{2,}" );
49
-
50
48
private final Class <? extends Annotation > annotationType ;
51
49
private final String mappingAttributeName ;
52
50
@@ -213,14 +211,18 @@ private static String cleanup(String mapping) {
213
211
214
212
String part = parts [i ];
215
213
214
+ if (!StringUtils .hasText (part )) {
215
+ continue ;
216
+ }
217
+
216
218
if (i != 0 ) {
217
219
result .append ("/" );
218
220
}
219
221
220
222
result .append (part .contains (":" ) ? cleanupPart (part ) : part );
221
223
}
222
224
223
- return MULTIPLE_SLASHES . matcher ( result . toString ()). replaceAll ("/" );
225
+ return ( mapping . endsWith ( "/" ) ? result . append ("/" ) : result ). toString ( );
224
226
}
225
227
226
228
private static String cleanupPart (String part ) {
Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ void extractsMultipleRegularExpressionVariablesCorrectly() throws Exception {
179
179
assertThat (discoverer .getMapping (method )).isEqualTo ("/type/spring-web/{symbolicName}-{version}{extension}" );
180
180
}
181
181
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
+
182
190
@ RequestMapping ("/type" )
183
191
interface MyController {
184
192
@@ -267,4 +275,12 @@ interface MultipleMappingsController {
267
275
@ RequestMapping ({ "/method" , "/methodAlias" })
268
276
void method ();
269
277
}
278
+
279
+ // #1468
280
+
281
+ interface TrailingSlashes {
282
+
283
+ @ RequestMapping ("/api/myentities/" )
284
+ Object trailingSlash ();
285
+ }
270
286
}
You can’t perform that action at this time.
0 commit comments