Skip to content

Commit c61f53a

Browse files
committed
Copy Query to Parameters
Issue gh-17450
1 parent 50bdaeb commit c61f53a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

web/src/test/java/org/springframework/security/web/servlet/TestMockHttpServletRequests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.security.web.servlet;
1818

1919
import java.util.LinkedHashMap;
20+
import java.util.List;
2021
import java.util.Map;
2122
import java.util.function.Consumer;
2223
import java.util.regex.Matcher;
@@ -27,6 +28,7 @@
2728
import org.springframework.http.HttpMethod;
2829
import org.springframework.mock.web.MockHttpServletRequest;
2930
import org.springframework.util.StringUtils;
31+
import org.springframework.web.util.UriComponentsBuilder;
3032

3133
public final class TestMockHttpServletRequests {
3234

@@ -149,6 +151,14 @@ public Builder serverName(String serverName) {
149151

150152
public MockHttpServletRequest build() {
151153
MockHttpServletRequest request = new MockHttpServletRequest();
154+
Map<String, List<String>> params = UriComponentsBuilder.fromUriString("?" + this.queryString)
155+
.build()
156+
.getQueryParams();
157+
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
158+
for (String value : entry.getValue()) {
159+
request.addParameter(entry.getKey(), value);
160+
}
161+
}
152162
applyElement(request::setContextPath, this.contextPath);
153163
applyElement(request::setContextPath, this.contextPath);
154164
applyElement(request::setMethod, this.method.name());

0 commit comments

Comments
 (0)