Ryan
Ryan

Reputation: 2084

UTF-16 Surrogate Pairs in Java JNDI LDAP Calls

I am seeing exceptions when issuing JNDI calls that include UTF-16 surrogate pairs. Here is some example Java code:

DirContext context = getContext();
String name = "\u5653\ud840\udc0b";
// String name = "渚噓"; //Same result if I use the actual characters
String distinguishedName = "cn=" + name + ",ou=users,dc=example,dc=com";
Attribute objectClass = new BasicAttribute("objectClass", "person");
Attribute userSn = new BasicAttribute("sn", "sn");

Attributes entry = new BasicAttributes();
entry.put(userSn);
entry.put(objectClass);

context.createSubcontext(distinguishedName, entry);

Results in:

Exception in thread "main" javax.naming.NamingException: [LDAP: error code 80 - OTHER: failed for MessageType : ADD_REQUEST
: ERR_13247_INVALID_VALUE_CANT_NORMALIZE Invalid upValue, it can't be normalized:
java.lang.IllegalArgumentException: ERR_13247_INVALID_VALUE_CANT_NORMALIZE Invalid upValue, it can't be normalized
    at org.apache.directory.api.ldap.model.entry.Value.<init>(Value.java:379)

The same code works if I remove the surrogate pair (\ud840\udc0b). This would appear to be a limitation of The Apache Directory™ Project (ApacheDS), the local LDAP server I'm using. However, I've tested with other LDAP implementations (eg. IBM Tivoli Directory Server) and also get errors:

javax.naming.InvalidNameException: cn=噓,cn=groups,dc=example,dc=com: [LDAP: error code 34 - Invalid DN Syntax]

and:

javax.naming.NameNotFoundException: [LDAP: error code 32 - NO_SUCH_OBJECT: failed for MessageType : ADD_REQUEST
: ERR_268 Cannot find a partition for cn=噓𠀋,dc=example,dc=com]; remaining name 'cn=噓𠀋,dc=example,dc=com'

In each test, everything functions correctly when I remove the surrogate pairs. Is there a limitation in LDAP?

Upvotes: 1

Views: 155

Answers (0)

Related Questions