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:
Rob Winch
2016-04-15 10:23:00 -05:00
parent 64d4e91b6e
commit 87ed8e939c
2 changed files with 33 additions and 7 deletions

View File

@@ -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()) {