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
/**
40
40
*/
41
41
public class AnnotationMappingDiscoverer implements MappingDiscoverer {
42
42
43
- private static final Pattern MULTIPLE_SLASHES = Pattern .compile ("/{2,}" );
44
-
45
43
private final Class <? extends Annotation > annotationType ;
46
44
private final String mappingAttributeName ;
47
45
@@ -193,14 +191,18 @@ private static String cleanup(String mapping) {
193
191
194
192
String part = parts [i ];
195
193
194
+ if (!StringUtils .hasText (part )) {
195
+ continue ;
196
+ }
197
+
196
198
if (i != 0 ) {
197
199
result .append ("/" );
198
200
}
199
201
200
202
result .append (part .contains (":" ) ? cleanupPart (part ) : part );
201
203
}
202
204
203
- return MULTIPLE_SLASHES . matcher ( result . toString ()). replaceAll ("/" );
205
+ return ( mapping . endsWith ( "/" ) ? result . append ("/" ) : result ). toString ( );
204
206
}
205
207
206
208
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 // #1470
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
+ // #1470
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