From 1726794341e9e58256004f040b276fa579161b6b Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Thu, 20 Sep 2012 10:11:22 -0500 Subject: Renamed escapeDN() into escapeRDNValue(). The escapeDN() has been renamed into escapeRDNValue() for better clarity. Ticket #193 --- .../src/com/netscape/cmsutil/ldap/LDAPUtil.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'base/util/src/com') diff --git a/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java b/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java index ca894d87c..b02ffee78 100644 --- a/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java +++ b/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java @@ -63,47 +63,47 @@ public class LDAPUtil { /** * This method escapes special characters for LDAP DN (RFC 1779). */ - public static String escapeDN(Object value) { - return LDAPUtil.escapeDN(value.toString(), false); + public static String escapeRDNValue(Object value) { + return LDAPUtil.escapeRDNValue(value.toString(), false); } - public static String escapeDN(String v, boolean doubleEscape) { - StringBuffer result = new StringBuffer(); + public static String escapeRDNValue(String value, boolean doubleEscape) { + StringBuilder sb = new StringBuilder(); // Do we need to escape any characters - for (int i = 0; i < v.length(); i++) { - int c = v.charAt(i); + for (int i = 0; i < value.length(); i++) { + int c = value.charAt(i); if (c == ',' || c == '=' || c == '+' || c == '<' || c == '>' || c == '#' || c == ';' || c == '\r' || c == '\n' || c == '\\' || c == '"') { - if ((c == 0x5c) && ((i + 1) < v.length())) { - int nextC = v.charAt(i + 1); + if ((c == 0x5c) && ((i + 1) < value.length())) { + int nextC = value.charAt(i + 1); if ((c == 0x5c) && (nextC == ',' || nextC == '=' || nextC == '+' || nextC == '<' || nextC == '>' || nextC == '#' || nextC == ';' || nextC == '\r' || nextC == '\n' || nextC == '\\' || nextC == '"')) { if (doubleEscape) - result.append('\\'); + sb.append('\\'); } else { - result.append('\\'); + sb.append('\\'); if (doubleEscape) - result.append('\\'); + sb.append('\\'); } } else { - result.append('\\'); + sb.append('\\'); if (doubleEscape) - result.append('\\'); + sb.append('\\'); } } if (c == '\r') { - result.append("0D"); + sb.append("0D"); } else if (c == '\n') { - result.append("0A"); + sb.append("0A"); } else { - result.append((char) c); + sb.append((char) c); } } - return result.toString(); + return sb.toString(); } public static void importLDIF(LDAPConnection conn, String filename, ArrayList errors) throws IOException { -- cgit