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 24
24
import java .util .Collection ;
25
25
import java .util .Collections ;
26
26
import java .util .List ;
27
- import java .util .regex .Pattern ;
28
27
29
28
import org .springframework .http .HttpMethod ;
30
29
import org .springframework .lang .Nullable ;
31
30
import org .springframework .util .Assert ;
31
+ import org .springframework .util .StringUtils ;
32
32
import org .springframework .web .bind .annotation .RequestMethod ;
33
33
34
34
/**
42
42
@ Deprecated
43
43
public class AnnotationMappingDiscoverer implements MappingDiscoverer {
44
44
45
- private static final Pattern MULTIPLE_SLASHES = Pattern .compile ("/{2,}" );
46
-
47
45
private final Class <? extends Annotation > annotationType ;
48
46
private final String mappingAttributeName ;
49
47
@@ -195,14 +193,18 @@ private static String cleanup(String mapping) {
195
193
196
194
String part = parts [i ];
197
195
196
+ if (!StringUtils .hasText (part )) {
197
+ continue ;
198
+ }
199
+
198
200
if (i != 0 ) {
199
201
result .append ("/" );
200
202
}
201
203
202
204
result .append (part .contains (":" ) ? cleanupPart (part ) : part );
203
205
}
204
206
205
- return MULTIPLE_SLASHES . matcher ( result . toString ()). replaceAll ("/" );
207
+ return ( mapping . endsWith ( "/" ) ? result . append ("/" ) : result ). toString ( );
206
208
}
207
209
208
210
private static String cleanupPart (String part ) {
Original file line number Diff line number Diff line change @@ -168,6 +168,14 @@ void extractsMultipleRegularExpressionVariablesCorrectly() throws Exception {
168
168
assertThat (discoverer .getMapping (method )).isEqualTo ("/type/spring-web/{symbolicName}-{version}{extension}" );
169
169
}
170
170
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
+
171
179
@ RequestMapping ("/type" )
172
180
interface MyController {
173
181
@@ -253,4 +261,12 @@ interface MultipleMappingsController {
253
261
@ RequestMapping ({ "/method" , "/methodAlias" })
254
262
void method ();
255
263
}
264
+
265
+ // #1469
266
+
267
+ interface TrailingSlashes {
268
+
269
+ @ RequestMapping ("/api/myentities/" )
270
+ Object trailingSlash ();
271
+ }
256
272
}
You can’t perform that action at this time.
0 commit comments