diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index 2a4777fe22..77743aa9a8 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -69,7 +69,12 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { } - private final UrlPathHelper pathHelper = new UrlPathHelper(); + private final UrlPathHelper pathHelper; + + public ForwardedHeaderFilter() { + this.pathHelper = new UrlPathHelper(); + this.pathHelper.setUrlDecode(false); + } @Override diff --git a/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java index 3e46124149..26d55b596c 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java @@ -106,6 +106,18 @@ public class ForwardedHeaderFilterTests { assertEquals("", actual.getContextPath()); assertEquals("/path/", actual.getRequestURI()); } + + @Test + public void requestUriPreserveEncoding() throws Exception { + this.request.setContextPath("/app"); + this.request.setRequestURI("/app/path%20with%20spaces/"); + HttpServletRequest actual = filterAndGetWrappedRequest(); + + assertEquals("/app", actual.getContextPath()); + assertEquals("/app/path%20with%20spaces/", actual.getRequestURI()); + assertEquals("http://localhost/app/path%20with%20spaces/", actual.getRequestURL().toString()); + } + @Test public void requestUriEqualsContextPath() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/");