Copy Query to Parameters

Issue gh-17450
This commit is contained in:
Josh Cummings 2025-09-22 12:17:24 -06:00
parent 50bdaeb100
commit c61f53ad64
No known key found for this signature in database
GPG Key ID: 869B37A20E876129
1 changed files with 10 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package org.springframework.security.web.servlet; package org.springframework.security.web.servlet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -27,6 +28,7 @@ import java.util.stream.Stream;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponentsBuilder;
public final class TestMockHttpServletRequests { public final class TestMockHttpServletRequests {
@ -149,6 +151,14 @@ public final class TestMockHttpServletRequests {
public MockHttpServletRequest build() { public MockHttpServletRequest build() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
Map<String, List<String>> params = UriComponentsBuilder.fromUriString("?" + this.queryString)
.build()
.getQueryParams();
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
for (String value : entry.getValue()) {
request.addParameter(entry.getKey(), value);
}
}
applyElement(request::setContextPath, this.contextPath); applyElement(request::setContextPath, this.contextPath);
applyElement(request::setContextPath, this.contextPath); applyElement(request::setContextPath, this.contextPath);
applyElement(request::setMethod, this.method.name()); applyElement(request::setMethod, this.method.name());