#1468 - Mapping discoverer now keeps trailing slashes around.
This commit is contained in:
@@ -25,13 +25,13 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
@@ -45,8 +45,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@Deprecated
|
||||
public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
|
||||
private static final Pattern MULTIPLE_SLASHES = Pattern.compile("/{2,}");
|
||||
|
||||
private final Class<? extends Annotation> annotationType;
|
||||
private final String mappingAttributeName;
|
||||
|
||||
@@ -213,6 +211,10 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
|
||||
String part = parts[i];
|
||||
|
||||
if (!StringUtils.hasText(part)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
result.append("/");
|
||||
}
|
||||
@@ -220,7 +222,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) {
|
||||
|
||||
@@ -179,6 +179,14 @@ class AnnotationMappingDiscovererUnitTest {
|
||||
assertThat(discoverer.getMapping(method)).isEqualTo("/type/spring-web/{symbolicName}-{version}{extension}");
|
||||
}
|
||||
|
||||
@Test // #1468
|
||||
void keepsTrailingSlash() throws Exception {
|
||||
|
||||
Method method = TrailingSlashes.class.getMethod("trailingSlash");
|
||||
|
||||
assertThat(discoverer.getMapping(method)).isEqualTo("/api/myentities/");
|
||||
}
|
||||
|
||||
@RequestMapping("/type")
|
||||
interface MyController {
|
||||
|
||||
@@ -267,4 +275,12 @@ class AnnotationMappingDiscovererUnitTest {
|
||||
@RequestMapping({ "/method", "/methodAlias" })
|
||||
void method();
|
||||
}
|
||||
|
||||
// #1468
|
||||
|
||||
interface TrailingSlashes {
|
||||
|
||||
@RequestMapping("/api/myentities/")
|
||||
Object trailingSlash();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user