Skip to content

Commit 5ce9067

Browse files
committed
Clean trailing slash from endpoints.web.base-path
Fixes gh-11021
1 parent 4a41c02 commit 5ce9067

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Set;
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.util.StringUtils;
2526

2627
/**
2728
* Configuration properties for web management endpoints.
@@ -59,7 +60,14 @@ public String getBasePath() {
5960
}
6061

6162
public void setBasePath(String basePath) {
62-
this.basePath = basePath;
63+
this.basePath = cleanBasePath(basePath);
64+
}
65+
66+
private String cleanBasePath(String basePath) {
67+
if (StringUtils.hasText(basePath) && basePath.endsWith("/")) {
68+
return basePath.substring(0, basePath.length() - 1);
69+
}
70+
return basePath;
6371
}
6472

6573
public Set<String> getExpose() {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointPropertiesTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ public void defaultBasePathShouldBeApplication() throws Exception {
3333
assertThat(properties.getBasePath()).isEqualTo("/application");
3434
}
3535

36+
@Test
37+
public void basePathShouldBeCleaned() throws Exception {
38+
WebEndpointProperties properties = new WebEndpointProperties();
39+
properties.setBasePath("/");
40+
assertThat(properties.getBasePath()).isEqualTo("");
41+
}
3642
}

0 commit comments

Comments
 (0)