Merge pull request #16165 from mrifni

* pr/16165:
  Polish "Trim trailing whitespace from spring.server.servlet.context-path"
  Trim trailing whitespace from spring.server.servlet.context-path
pull/16219/head
Stephane Nicoll 6 years ago
commit 55e5bafcfc

@ -231,10 +231,11 @@ public class ServerProperties {
}
private String cleanContextPath(String contextPath) {
if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) {
return contextPath.substring(0, contextPath.length() - 1);
String candidate = StringUtils.trimWhitespace(contextPath);
if (StringUtils.hasText(candidate) && candidate.endsWith("/")) {
return candidate.substring(0, candidate.length() - 1);
}
return contextPath;
return candidate;
}
public String getApplicationDisplayName() {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -149,6 +149,32 @@ public class ServerPropertiesTests {
assertThat(this.properties.getServlet().getContextPath()).isEqualTo("");
}
@Test
public void testContextPathWithLeadingWhitespace() {
bind("server.servlet.context-path", " /assets");
assertThat(this.properties.getServlet().getContextPath()).isEqualTo("/assets");
}
@Test
public void testContextPathWithTrailingWhitespace() {
bind("server.servlet.context-path", "/assets/copy/ ");
assertThat(this.properties.getServlet().getContextPath())
.isEqualTo("/assets/copy");
}
@Test
public void testContextPathWithLeadingAndTrailingWhitespace() {
bind("server.servlet.context-path", " /assets ");
assertThat(this.properties.getServlet().getContextPath()).isEqualTo("/assets");
}
@Test
public void testContextPathWithLeadingAndTrailingWhitespaceAndContextWithSpace() {
bind("server.servlet.context-path", " /assets /copy/ ");
assertThat(this.properties.getServlet().getContextPath())
.isEqualTo("/assets /copy");
}
@Test
public void testCustomizeUriEncoding() {
bind("server.tomcat.uri-encoding", "US-ASCII");

Loading…
Cancel
Save