Clean trailing slash from endpoints.web.base-path
Fixes gh-11021
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Configuration properties for web management endpoints.
|
||||
@@ -59,7 +60,14 @@ public class WebEndpointProperties {
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
this.basePath = cleanBasePath(basePath);
|
||||
}
|
||||
|
||||
private String cleanBasePath(String basePath) {
|
||||
if (StringUtils.hasText(basePath) && basePath.endsWith("/")) {
|
||||
return basePath.substring(0, basePath.length() - 1);
|
||||
}
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public Set<String> getExpose() {
|
||||
|
||||
@@ -33,4 +33,10 @@ public class WebEndpointPropertiesTests {
|
||||
assertThat(properties.getBasePath()).isEqualTo("/application");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basePathShouldBeCleaned() throws Exception {
|
||||
WebEndpointProperties properties = new WebEndpointProperties();
|
||||
properties.setBasePath("/");
|
||||
assertThat(properties.getBasePath()).isEqualTo("");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user