From 1367bcce8238a78727299ed67b43cc5a44de458d Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Mon, 05 Mar 2012 17:25:51 +0000
Subject: [PATCH] Fix for OPENDJ-432: LDAPURL doesn't always url-decode baseDN

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/LDAPURLTestCase.java |    5 ++---
 opendj-sdk/opends/src/server/org/opends/server/types/LDAPURL.java                                 |   34 ++++------------------------------
 2 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/LDAPURL.java b/opendj-sdk/opends/src/server/org/opends/server/types/LDAPURL.java
index 4f0e449..b7f2174 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/LDAPURL.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/LDAPURL.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS.
  */
 package org.opends.server.types;
 import org.opends.messages.Message;
@@ -462,19 +463,19 @@
     pos = url.indexOf('?', startPos);
     if (pos < 0)
     {
-      baseDNString = url.substring(startPos);
+      baseDNString = urlDecode(url.substring(startPos));
       startPos = length;
     }
     else
     {
-      baseDNString = url.substring(startPos, pos);
+      baseDNString = urlDecode(url.substring(startPos, pos));
       startPos = pos+1;
     }
 
     DN baseDN;
     if (fullyDecode)
     {
-      baseDN = DN.decode(urlDecode(baseDNString));
+      baseDN = DN.decode(baseDNString);
     }
     else
     {
@@ -866,33 +867,6 @@
 
 
   /**
-   * Encodes the provided string portion for inclusion in an LDAP URL.
-   *
-   * @param  s            The string portion to be encoded.
-   * @param  isExtension  Indicates whether the provided component is
-   *                      an extension and therefore needs to have
-   *                      commas encoded.
-   *
-   * @return  The URL-encoded version of the string portion.
-   */
-  private static String urlEncode(String s, boolean isExtension)
-  {
-    if (s == null)
-    {
-      return "";
-    }
-
-
-    int length = s.length();
-    StringBuilder buffer = new StringBuilder(length);
-    urlEncode(s, isExtension, buffer);
-
-    return buffer.toString();
-  }
-
-
-
-  /**
    * Encodes the provided string portion for inclusion in an LDAP URL
    * and appends it to the provided buffer.
    *
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/LDAPURLTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/LDAPURLTestCase.java
index f460e0b..3825a13 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/LDAPURLTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/LDAPURLTestCase.java
@@ -75,9 +75,8 @@
         { "ldap:///dc=example,dc=com???(cn=test)", "dc=example,dc=com",
             "(cn=test)", true },
         /* DN encoding: triple back-slash required for Java and DN escaping */
-// Uncomment when OPENDJ-432 fix is committed.
-//        { "ldap:///dc=%5c%22example%5c%22,dc=com???(cn=test)",
-//            "dc=\\\"example\\\",dc=com", "(cn=test)", false },
+        { "ldap:///dc=%5c%22example%5c%22,dc=com???(cn=test)",
+            "dc=\\\"example\\\",dc=com", "(cn=test)", false },
         { "ldap:///dc=%5c%22example%5c%22,dc=com???(cn=test)",
             "dc=\\\"example\\\",dc=com", "(cn=test)", true },
         /* Filter encoding */

--
Gitblit v1.10.0