From 7bea06045c4cb1b9fa324c3d5b452a634e5a44aa Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 12 Dec 2023 09:46:38 +0100 Subject: [PATCH] WW-5370 Simplifies code --- .../apache/struts2/dispatcher/HttpParameters.java | 8 ++++---- .../struts2/dispatcher/HttpParametersTest.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 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 e44f062739..f585c65552 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java @@ -49,7 +49,7 @@ public static Builder create() { public HttpParameters remove(Set paramsToRemove) { for (String paramName : paramsToRemove) { - parameters.entrySet().removeIf(p -> p.getKey().equalsIgnoreCase(paramName)); + parameters.remove(paramName); } return this; } @@ -112,10 +112,10 @@ public boolean containsValue(Object value) { @Override public Parameter get(Object key) { - if (key != null && contains(String.valueOf(key))) { - return parameters.get(key); + if (key != null) { + return parameters.get(String.valueOf(key)); } else { - return new Parameter.Empty(String.valueOf(key)); + return null; } } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/HttpParametersTest.java b/core/src/test/java/org/apache/struts2/dispatcher/HttpParametersTest.java index 7c2efbc125..b8b0a3038a 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/HttpParametersTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/HttpParametersTest.java @@ -23,6 +23,8 @@ import java.util.HashMap; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class HttpParametersTest { @@ -40,6 +42,18 @@ public void shouldGetBeCaseInsensitive() { assertEquals("value1", params.get("pAraM1").getValue()); } + @Test + public void shouldRemoveBeCaseInsensitive() { + // given + HttpParameters params = HttpParameters.create(new HashMap() {{ + put("param1", "value1"); + }}).build(); + + // then + assertFalse(params.remove("Param1").contains("param1")); + assertNull(params.get("param1")); + } + @Test public void shouldAppendSameParamsIgnoringCase() { // given