Polish
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -62,14 +62,15 @@ import org.springframework.web.util.UriUtils;
|
|||||||
import org.springframework.web.util.UrlPathHelper;
|
import org.springframework.web.util.UrlPathHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default builder for {@link MockHttpServletRequest} required as input to perform
|
* Default builder for {@link MockHttpServletRequest} required as input to
|
||||||
* requests in {@link MockMvc}.
|
* perform requests in {@link MockMvc}.
|
||||||
*
|
*
|
||||||
* <p>Application tests will typically access this builder through the static factory
|
* <p>Application tests will typically access this builder through the static
|
||||||
* methods in {@link MockMvcRequestBuilders}.
|
* factory methods in {@link MockMvcRequestBuilders}.
|
||||||
*
|
*
|
||||||
* <p>Although this class cannot be extended, additional ways to initialize the
|
* <p>This class is not open for extension. To apply custom initialization to
|
||||||
* {@code MockHttpServletRequest} can be plugged in via {@link #with(RequestPostProcessor)}.
|
* the created {@code MockHttpServletRequest}, please use the
|
||||||
|
* {@link #with(RequestPostProcessor)} extension point.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
@@ -81,7 +82,8 @@ import org.springframework.web.util.UrlPathHelper;
|
|||||||
public class MockHttpServletRequestBuilder
|
public class MockHttpServletRequestBuilder
|
||||||
implements ConfigurableSmartRequestBuilder<MockHttpServletRequestBuilder>, Mergeable {
|
implements ConfigurableSmartRequestBuilder<MockHttpServletRequestBuilder>, Mergeable {
|
||||||
|
|
||||||
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||||
|
|
||||||
|
|
||||||
private final String method;
|
private final String method;
|
||||||
|
|
||||||
@@ -699,7 +701,8 @@ public class MockHttpServletRequestBuilder
|
|||||||
"Invalid servlet path [" + this.servletPath + "] for request URI [" + requestUri + "]");
|
"Invalid servlet path [" + this.servletPath + "] for request URI [" + requestUri + "]");
|
||||||
}
|
}
|
||||||
String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
|
String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
|
||||||
this.pathInfo = (StringUtils.hasText(extraPath) ? this.urlPathHelper.decodeRequestString(request, extraPath) : null);
|
this.pathInfo = (StringUtils.hasText(extraPath) ?
|
||||||
|
urlPathHelper.decodeRequestString(request, extraPath) : null);
|
||||||
}
|
}
|
||||||
request.setPathInfo(this.pathInfo);
|
request.setPathInfo(this.pathInfo);
|
||||||
}
|
}
|
||||||
@@ -714,7 +717,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {
|
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {
|
||||||
HttpInputMessage message = new HttpInputMessage() {
|
HttpInputMessage message = new HttpInputMessage() {
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() {
|
||||||
return (content != null ? new ByteArrayInputStream(content) : StreamUtils.emptyInput());
|
return (content != null ? new ByteArrayInputStream(content) : StreamUtils.emptyInput());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class MockHttpServletRequestBuilderTests {
|
|||||||
assertNull(request.getPathInfo());
|
assertNull(request.getPathInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // SPR-16453
|
||||||
public void pathInfoIsDecoded() {
|
public void pathInfoIsDecoded() {
|
||||||
this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/hotels 42");
|
this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/hotels 42");
|
||||||
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
|
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
|
||||||
|
|||||||
Reference in New Issue
Block a user