HtmlUnitRequestBuilder decodes parameter names
Previously HtmlUnitRequestBuilder did not decode parameter names. This means if a parameter like row[0] was submittted it would be encoded as row%5B0%5D When the HttpServletRequest was created the parameter name would not be decoded so the parameter name row[0] would not be found. This commit ensures that HTTP parameter names are decoded. Issue SPR-14177
This commit is contained in:
@@ -360,14 +360,10 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
private void params(MockHttpServletRequest request, UriComponents uriComponents) {
|
||||
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
String urlDecodedName = urlDecode(name);
|
||||
for (String value : entry.getValue()) {
|
||||
try {
|
||||
value = (value != null ? URLDecoder.decode(value, "UTF-8") : "");
|
||||
request.addParameter(name, value);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
value = (value != null ? urlDecode(value) : "");
|
||||
request.addParameter(urlDecodedName, value);
|
||||
}
|
||||
}
|
||||
for (NameValuePair param : this.webRequest.getRequestParameters()) {
|
||||
@@ -375,6 +371,15 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
}
|
||||
}
|
||||
|
||||
private String urlDecode(String value) {
|
||||
try {
|
||||
return URLDecoder.decode(value, "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Locale parseLocale(String locale) {
|
||||
Matcher matcher = LOCALE_PATTERN.matcher(locale);
|
||||
if (!matcher.matches()) {
|
||||
|
||||
Reference in New Issue
Block a user