Fix for OPENDJ-432: LDAPURL doesn't always url-decode baseDN
Thanks to Auke Schrijnen for contributing the bug fix.
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.types; |
| | | import org.opends.messages.Message; |
| | |
| | | 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 |
| | | { |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | * |
| | |
| | | { "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 */ |