Clean trailing slash from endpoints.web.base-path

Fixes gh-11021
This commit is contained in:
Madhura Bhave
2017-11-17 12:00:55 -08:00
parent 4a41c02926
commit 5ce9067e30
2 changed files with 15 additions and 1 deletions

View File

@@ -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() {

View File

@@ -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("");
}
}