mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
05.25.2012 1367bcce8238a78727299ed67b43cc5a44de458d
Fix for OPENDJ-432: LDAPURL doesn't always url-decode baseDN

Thanks to Auke Schrijnen for contributing the bug fix.
2 files modified
39 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/types/LDAPURL.java 34 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/LDAPURLTestCase.java 5 ●●●●● patch | view | raw | blame | history
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.
   *
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 */