From 747e73cd929a7d48f757cbe358f443f2610912f9 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 09 Mar 2007 20:08:29 +0000
Subject: [PATCH] Fix a problem that prevented the server from handling attribute options in a case-insensitive manner.

---
 opends/src/server/org/opends/server/types/Attribute.java                                       |   32 ++++++++++++---
 opends/tests/unit-tests-testng/src/server/org/opends/server/types/SearchFilterTests.java       |   11 +++--
 opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java |   19 +++++++++
 3 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/opends/src/server/org/opends/server/types/Attribute.java b/opends/src/server/org/opends/server/types/Attribute.java
index f862a5a..d649300 100644
--- a/opends/src/server/org/opends/server/types/Attribute.java
+++ b/opends/src/server/org/opends/server/types/Attribute.java
@@ -59,16 +59,20 @@
 
 
   // The attribute type for this attribute.
-  private AttributeType attributeType;
+  private final AttributeType attributeType;
 
   // The set of values for this attribute.
   private LinkedHashSet<AttributeValue> values;
 
   // The set of options for this attribute.
-  private LinkedHashSet<String> options;
+  private final LinkedHashSet<String> options;
+
+  // The set of options for this attribute, formatted in all lowercase
+  // characters.
+  private final LinkedHashSet<String> lowerOptions;
 
   // The name of this attribute as provided by the end user.
-  private String name;
+  private final String name;
 
 
 
@@ -84,6 +88,8 @@
     this.name          = attributeType.getPrimaryName();
     this.options       = new LinkedHashSet<String>(0);
     this.values        = new LinkedHashSet<AttributeValue>();
+
+    lowerOptions = options;
   }
 
 
@@ -101,6 +107,8 @@
     this.name          = name;
     this.options       = new LinkedHashSet<String>(0);
     this.values        = new LinkedHashSet<AttributeValue>();
+
+    lowerOptions = options;
   }
 
 
@@ -120,6 +128,8 @@
     this.name          = name;
     this.options       = new LinkedHashSet<String>(0);
 
+    lowerOptions = options;
+
     if (values == null)
     {
       this.values = new LinkedHashSet<AttributeValue>();
@@ -150,6 +160,8 @@
     this.values.add(new AttributeValue(this.attributeType,
                                        valueString));
     this.options = new LinkedHashSet<String>(0);
+
+    lowerOptions = options;
   }
 
 
@@ -173,10 +185,16 @@
     if (options == null)
     {
       this.options = new LinkedHashSet<String>(0);
+      lowerOptions = options;
     }
     else
     {
       this.options = options;
+      lowerOptions = new LinkedHashSet<String>();
+      for (String option : options)
+      {
+        lowerOptions.add(toLowerCase(option));
+      }
     }
 
     if (values == null)
@@ -237,7 +255,7 @@
    */
   public boolean hasOption(String option)
   {
-    return options.contains(option);
+    return lowerOptions.contains(toLowerCase(option));
   }
 
 
@@ -250,7 +268,7 @@
    */
   public boolean hasOptions()
   {
-    return ((options != null) && (! options.isEmpty()));
+    return (! options.isEmpty());
   }
 
 
@@ -275,7 +293,7 @@
 
     for (String option : options)
     {
-      if (! this.options.contains(option))
+      if (! lowerOptions.contains(toLowerCase(option)))
       {
         return false;
       }
@@ -316,7 +334,7 @@
 
     for (String s : options)
     {
-      if (! this.options.contains(s))
+      if (! lowerOptions.contains(toLowerCase(s)))
       {
         return false;
       }
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
index 2c1ca29..9bbbafb 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
@@ -398,6 +398,25 @@
   }
 
   @Test
+  public void testCompareOptions3()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+
+    CompareOperation compareOperation =
+         new CompareOperation(conn, InternalClientConnection.nextOperationID(),
+                              InternalClientConnection.nextMessageID(),
+                              new ArrayList<Control>(),
+                              new ASN1OctetString(entry.getDN().toString()),
+                              "givenName;lAnG-En",
+                              new ASN1OctetString("Rodney"));
+
+    compareOperation.run();
+    assertEquals(compareOperation.getResultCode(),
+                 ResultCode.COMPARE_TRUE);
+  }
+
+  @Test
   public void testCompareTrueAssertion() throws Exception
   {
     InvocationCounterPlugin.resetAllCounters();
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/types/SearchFilterTests.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/types/SearchFilterTests.java
index 9be7d62..69883ec 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/types/SearchFilterTests.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/types/SearchFilterTests.java
@@ -369,15 +369,18 @@
 
             // attribute options
             {JOHN_SMITH_LDIF, "(cn;lang-en=Jonathan Smith)", true},
+            {JOHN_SMITH_LDIF, "(cn;lang-EN=Jonathan Smith)", true},
             {JOHN_SMITH_LDIF, "(cn;lang-en=Jonathan Smithe)", false},
             {JOHN_SMITH_LDIF, "(cn;lang-fr=Jonathan Smith)", false},
             {JOHN_SMITH_LDIF, "(cn;lang-en=*jon*an*)", true},
+            {JOHN_SMITH_LDIF, "(cn;lAnG-En=*jon*an*)", true},
 
             // attribute subtypes.  Enable this once 593 is fixed.
-//            {JOHN_SMITH_LDIF, "(name=John Smith)", true},
-//            {JOHN_SMITH_LDIF, "(name=*Smith*)", true},
-//            {JOHN_SMITH_LDIF, "(name;lang-en=Jonathan Smith)", true},  // ? maybe not
-//            {JOHN_SMITH_LDIF, "(name;lang-en=*Jonathan*)", true},  // ? maybe not
+            {JOHN_SMITH_LDIF, "(name=John Smith)", true},
+            {JOHN_SMITH_LDIF, "(name=*Smith*)", true},
+            {JOHN_SMITH_LDIF, "(name;lang-en=Jonathan Smith)", true},
+            {JOHN_SMITH_LDIF, "(name;lang-EN=Jonathan Smith)", true},
+            {JOHN_SMITH_LDIF, "(name;lang-en=*Jonathan*)", true},
 
             // Enable this once
 //            {JOHN_SMITH_LDIF, "(cn=*Jo**i*th*)", true},

--
Gitblit v1.10.0