Skip to content

Commit

Permalink
Decode servletPath in HtmlUnitRequestBuilder
Browse files Browse the repository at this point in the history
Closes gh-27837
  • Loading branch information
rstoyanchev committed Jan 11, 2022
1 parent 9346c89 commit 3477ec0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -57,6 +57,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UriUtils;

/**
* Internal class used to transform a {@link WebRequest} into a
Expand Down Expand Up @@ -262,6 +263,7 @@ private void servletPath(UriComponents uriComponents, MockHttpServletRequest req
String path = uriComponents.getPath();
String requestPath = (path != null ? path : "");
String servletPath = requestPath.substring(request.getContextPath().length());
servletPath = UriUtils.decode(servletPath, StandardCharsets.UTF_8);
request.setServletPath(servletPath);
}

Expand Down
Expand Up @@ -782,6 +782,16 @@ public void buildRequestServletPath() throws Exception {
assertThat(actualRequest.getServletPath()).isEqualTo("/this/here");
}

@Test // gh-27837
public void buildRequestServletPathWithEncodedUrl() throws Exception {
webRequest.setUrl(new URL("http://localhost/test/Fr%C3%BChling%20Sommer%20Herbst%20Winter"));

MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

assertThat(actualRequest.getRequestURI()).isEqualTo("/test/Fr%C3%BChling%20Sommer%20Herbst%20Winter");
assertThat(actualRequest.getServletPath()).isEqualTo("/Frühling Sommer Herbst Winter");
}

@Test
public void buildRequestSession() throws Exception {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
Expand Down

0 comments on commit 3477ec0

Please sign in to comment.