From c40978f8cd29d510f6b9d214db141dc6becc7342 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 12 Dec 2023 08:52:57 +0100 Subject: [PATCH] WW-5370 Uses TreeMap with case-insensitive comparator --- .../apache/struts2/dispatcher/HttpParameters.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java index f35d475837..e44f062739 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java @@ -34,7 +34,8 @@ public class HttpParameters implements Map { final private Map parameters; private HttpParameters(Map parameters) { - this.parameters = parameters; + this.parameters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + this.parameters.putAll(parameters); } @SuppressWarnings("rawtypes") @@ -43,7 +44,7 @@ public static Builder create(Map requestParameterMap) { } public static Builder create() { - return new Builder(new HashMap<>()); + return new Builder(new TreeMap<>(String.CASE_INSENSITIVE_ORDER)); } public HttpParameters remove(Set paramsToRemove) { @@ -60,7 +61,7 @@ public HttpParameters remove(final String paramToRemove) { } public boolean contains(String name) { - return parameters.keySet().stream().anyMatch(p -> p.equalsIgnoreCase(name)); + return parameters.containsKey(name); } /** @@ -112,10 +113,7 @@ public boolean containsValue(Object value) { @Override public Parameter get(Object key) { if (key != null && contains(String.valueOf(key))) { - return parameters.entrySet().stream() - .filter(p -> p.getKey().equalsIgnoreCase(String.valueOf(key))) - .findFirst().map(Entry::getValue) - .orElse(new Parameter.Empty(String.valueOf(key))); + return parameters.get(key); } else { return new Parameter.Empty(String.valueOf(key)); }