434386 - Request Dispatcher extracts args and prevents asyncIO.

Changed behavior of mergeQueryParameters() so that new query
parameters hide old query parameters, but they are accumulated for
getParameter() APIs.
This commit is contained in:
Simone Bordet 2014-05-12 13:08:17 +02:00
parent 8ce1840b88
commit e4d6768901
2 changed files with 14 additions and 23 deletions

View File

@ -2209,14 +2209,12 @@ public class Request implements HttpServletRequest
UrlEncoded.decodeTo(_queryString, oldQueryParams, getQueryEncoding(), -1);
}
MultiMap<String> mergedQueryParams = new MultiMap<>(newQueryParams);
boolean hasParamsInCommon = false;
MultiMap<String> mergedQueryParams = newQueryParams;
if (oldQueryParams != null)
{
// Parameters in the newQuery replace parameters of the oldQuery.
MultiMap<String> copy = new MultiMap<>(oldQueryParams);
hasParamsInCommon = copy.keySet().removeAll(newQueryParams.keySet());
mergedQueryParams.addAllValues(copy);
// Parameters values are accumulated.
mergedQueryParams = new MultiMap<>(newQueryParams);
mergedQueryParams.addAllValues(oldQueryParams);
}
setQueryParameters(mergedQueryParams);
@ -2224,22 +2222,15 @@ public class Request implements HttpServletRequest
if (updateQueryString)
{
// Build the new merged query string.
// Build the new merged query string, parameters in the
// new query string hide parameters in the old query string.
StringBuilder mergedQuery = new StringBuilder(newQuery);
if (hasParamsInCommon)
for (Map.Entry<String, List<String>> entry : mergedQueryParams.entrySet())
{
for (Map.Entry<String, List<String>> entry : mergedQueryParams.entrySet())
{
if (newQueryParams.containsKey(entry.getKey()))
continue;
for (String value : entry.getValue())
mergedQuery.append("&").append(entry.getKey()).append("=").append(value);
}
}
else
{
if (_queryString != null)
mergedQuery.append("&").append(_queryString);
if (newQueryParams.containsKey(entry.getKey()))
continue;
for (String value : entry.getValue())
mergedQuery.append("&").append(entry.getKey()).append("=").append(value);
}
setQueryString(mergedQuery.toString());

View File

@ -265,7 +265,7 @@ public class DispatcherForwardTest
{
// 1. request /one?a=1 + content a=2
// 1. forward /two?a=3
// 2. assert query => a=3 + params => a=3,2
// 2. assert query => a=3 + params => a=3,2,1
// 1. assert query => a=1 + params => a=1,2
final String query1 = "a=1";
@ -295,8 +295,8 @@ public class DispatcherForwardTest
checkThat(query2, Matchers.equalTo(req.getQueryString()));
String[] values = req.getParameterValues("a");
checkThat(values, Matchers.notNullValue());
checkThat(2, Matchers.equalTo(values.length));
checkThat(values, Matchers.arrayContainingInAnyOrder("3", "2"));
checkThat(3, Matchers.equalTo(values.length));
checkThat(values, Matchers.arrayContainingInAnyOrder("3", "2", "1"));
}
};