MockHttpServletRequestBuilder decodes pathInfo

Previously MockHttpServletRequestBuilder calculated the pathInfo from the
provided URL without decoding the value. This meant that the pathInfo
incorrectly included URL encoded values.

Now MockHttpServletRequestBuilder properly decodes the pathInfo.

Fixes: SPR-16453
This commit is contained in:
Rob Winch
2018-02-01 13:23:43 -06:00
committed by Rossen Stoyanchev
parent 609f173ebc
commit 0cd427bdd3
2 changed files with 12 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ import org.springframework.web.servlet.FlashMapManager;
import org.springframework.web.servlet.support.SessionFlashMapManager;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UriUtils;
import org.springframework.web.util.UrlPathHelper;
/**
* Default builder for {@link MockHttpServletRequest} required as input to perform
@@ -80,6 +81,8 @@ import org.springframework.web.util.UriUtils;
public class MockHttpServletRequestBuilder
implements ConfigurableSmartRequestBuilder<MockHttpServletRequestBuilder>, Mergeable {
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
private final String method;
private final URI url;
@@ -696,7 +699,7 @@ public class MockHttpServletRequestBuilder
"Invalid servlet path [" + this.servletPath + "] for request URI [" + requestUri + "]");
}
String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
this.pathInfo = (StringUtils.hasText(extraPath) ? extraPath : null);
this.pathInfo = (StringUtils.hasText(extraPath) ? this.urlPathHelper.decodeRequestString(request, extraPath) : null);
}
request.setPathInfo(this.pathInfo);
}