From da79e610ea7a068766c547bf2fe99fdd60bfcb08 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Thu, 3 Feb 2022 17:56:17 -0700 Subject: [PATCH] Make NameAwareAttributes#remove Case-insensitive Closes gh-548 --- .../ldap/core/NameAwareAttributes.java | 2 +- .../ldap/core/NameAwareAttributesTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTest.java diff --git a/core/src/main/java/org/springframework/ldap/core/NameAwareAttributes.java b/core/src/main/java/org/springframework/ldap/core/NameAwareAttributes.java index a78cf7f9..3bf11b20 100644 --- a/core/src/main/java/org/springframework/ldap/core/NameAwareAttributes.java +++ b/core/src/main/java/org/springframework/ldap/core/NameAwareAttributes.java @@ -99,7 +99,7 @@ public final class NameAwareAttributes implements Attributes { @Override public Attribute remove(String attrID) { Assert.hasLength(attrID, "Attribute ID must not be empty"); - return attributes.remove(attrID); + return attributes.remove(attrID.toLowerCase()); } @Override diff --git a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTest.java b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTest.java new file mode 100644 index 00000000..66de9b96 --- /dev/null +++ b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTest.java @@ -0,0 +1,25 @@ +package org.springframework.ldap.core; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NameAwareAttributesTest { + // gh-548 + @Test + public void removeWhenDifferentCaseThenRemoves() { + NameAwareAttributes attributes = new NameAwareAttributes(); + attributes.put("myID", "value"); + attributes.put("myOtherID", "othervalue"); + assertThat(attributes.size()).isEqualTo(2); + assertThat(attributes.get("myid").get()).isEqualTo("value"); + assertThat(attributes.get("myID").get()).isEqualTo("value"); + + attributes.remove("myid"); + assertThat(attributes.get("myID")).isNull(); + assertThat(attributes.size()).isEqualTo(1); + + attributes.remove("myOtherID"); + assertThat(attributes.size()).isEqualTo(0); + } +}