#1470 - Mapping discoverer now keeps trailing slashes around.
This commit is contained in:
@@ -24,11 +24,11 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
@@ -40,8 +40,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
*/
|
||||
public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
|
||||
private static final Pattern MULTIPLE_SLASHES = Pattern.compile("/{2,}");
|
||||
|
||||
private final Class<? extends Annotation> annotationType;
|
||||
private final String mappingAttributeName;
|
||||
|
||||
@@ -193,6 +191,10 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
|
||||
String part = parts[i];
|
||||
|
||||
if (!StringUtils.hasText(part)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
result.append("/");
|
||||
}
|
||||
@@ -200,7 +202,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
result.append(part.contains(":") ? cleanupPart(part) : part);
|
||||
}
|
||||
|
||||
return MULTIPLE_SLASHES.matcher(result.toString()).replaceAll("/");
|
||||
return (mapping.endsWith("/") ? result.append("/") : result).toString();
|
||||
}
|
||||
|
||||
private static String cleanupPart(String part) {
|
||||
|
||||
@@ -168,6 +168,14 @@ class AnnotationMappingDiscovererUnitTest {
|
||||
assertThat(discoverer.getMapping(method)).isEqualTo("/type/spring-web/{symbolicName}-{version}{extension}");
|
||||
}
|
||||
|
||||
@Test // #1470
|
||||
void keepsTrailingSlash() throws Exception {
|
||||
|
||||
Method method = TrailingSlashes.class.getMethod("trailingSlash");
|
||||
|
||||
assertThat(discoverer.getMapping(method)).isEqualTo("/api/myentities/");
|
||||
}
|
||||
|
||||
@RequestMapping("/type")
|
||||
interface MyController {
|
||||
|
||||
@@ -253,4 +261,12 @@ class AnnotationMappingDiscovererUnitTest {
|
||||
@RequestMapping({ "/method", "/methodAlias" })
|
||||
void method();
|
||||
}
|
||||
|
||||
// #1470
|
||||
|
||||
interface TrailingSlashes {
|
||||
|
||||
@RequestMapping("/api/myentities/")
|
||||
Object trailingSlash();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user