From 1e2e13b842106ba5b4d15714d23aab21379965a2 Mon Sep 17 00:00:00 2001 From: Mattias Arthursson Date: Sat, 31 Mar 2007 10:54:57 +0000 Subject: [PATCH] LDAP-30: RDN could not be parsed fully. --- .../ldap/core/LdapEncoder.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/spring-ldap/src/main/java/org/springframework/ldap/core/LdapEncoder.java b/spring-ldap/src/main/java/org/springframework/ldap/core/LdapEncoder.java index adcf31a3..f9c9c07d 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/core/LdapEncoder.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/core/LdapEncoder.java @@ -30,22 +30,9 @@ import org.springframework.ldap.BadLdapGrammarException; */ public class LdapEncoder { - static private String[] nameEscapeTable = new String[96]; + private static String[] nameEscapeTable = new String[96]; - static private String[] filterEscapeTable = new String['\\' + 1]; - - /** - * Pattern for matching escaped ldap name values. - * - * Double escaping: \ -> \\ (in pattern) -> \\\\ (in java string literal) - * - * Group 1: Hex escapes = \XX -> \p{XDigit}{2} Group 2: Ordinary escapes = - * \x -> \. Group 3: Anything but \ [^\\] - * - * Note that the \ is not part of the match. - */ - static private final Pattern VALUE_DECODE_PATTERN = Pattern - .compile("(?:\\\\(\\p{XDigit}{2}))|(?:\\\\(.))|([^\\\\])"); + private static String[] filterEscapeTable = new String['\\' + 1]; static { @@ -63,9 +50,7 @@ public class LdapEncoder { nameEscapeTable['+'] = "\\+"; nameEscapeTable['<'] = "\\<"; nameEscapeTable['>'] = "\\>"; - // nameEscapeTable['\''] = "\\"; nameEscapeTable['\"'] = "\\\""; - // nameEscapeTable['/'] = "\\" + toTwoCharHex('/'); nameEscapeTable['\\'] = "\\\\"; // Filter encoding table ------------------------------------- @@ -199,15 +184,17 @@ public class LdapEncoder { char currentChar = value.charAt(i); if (currentChar == '\\') { if (value.length() <= i + 1) { + // Ending with a single backslash is not allowed throw new BadLdapGrammarException( "Unexpected end of value " + "unterminated '\\'"); } else { char nextChar = value.charAt(i + 1); - if (nextChar == ',' | nextChar == '=' | nextChar == '+' - | nextChar == '<' | nextChar == '>' - | nextChar == '#' | nextChar == ';' - | nextChar == '\\' | nextChar == '\"' - | nextChar == ' ') { + if (nextChar == ',' || nextChar == '=' || nextChar == '+' + || nextChar == '<' || nextChar == '>' + || nextChar == '#' || nextChar == ';' + || nextChar == '\\' || nextChar == '\"' + || nextChar == ' ') { + // Normal backslash escape decoded.append(nextChar); i += 2; } else { @@ -227,6 +214,7 @@ public class LdapEncoder { } } } else { + // This character wasn't escaped - just append it decoded.append(currentChar); i++; }