Index: modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java =================================================================== --- modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java (revision 537153) +++ modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java (working copy) @@ -1360,6 +1360,29 @@ /** *
+ * Test method for 'javax.naming.ldap.LdapName.get(int)' + *
+ *+ * Here we are testing if this method retrieves a component of this LDAP + * name as a string, notice that the index must be in the range [0,size()). + *
+ *+ * The expected result is if the returned string by this method is the + * variable wich we create the Name. + *
+ */ + public void testGet007() throws Exception { + String test1 = "t=\\ test\\ +t1=\\ test1"; + LdapName ln1 = new LdapName(test1); + assertEquals(test1, ln1.get(0)); + + String test2 = "t=\\20\\ te\\ s\\20t\\20\\20 + t2 = test1\\20\\ "; + LdapName ln2 = new LdapName(test2); + assertEquals("t=\\ \\ te s t\\ +t2=test1\\ \\ ", ln2.get(0)); + } + + /** + ** Test method for 'javax.naming.ldap.LdapName.getRdn(int)' *
*Index: modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java =================================================================== --- modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java (revision 537153) +++ modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java (working copy) @@ -110,12 +110,23 @@ private static String getEscaped(char[] chars) { StringBuffer sb = new StringBuffer(); - for (int i = 0; i < chars.length; i++) { + int leftSpaceCnt = 0, rightSpaceCnt = 0; + int pos = chars.length - 1; + while (pos >= 0 && chars[pos] == ' ') { + rightSpaceCnt++; + pos--; + } + for (int i = 0; i <= pos && chars[i]==' '; i++) { + leftSpaceCnt++; + sb.append("\\ "); + } + for (int i = leftSpaceCnt; i < chars.length - rightSpaceCnt; i++) { if (isSpecialChar(chars, i)) { sb.append('\\'); } sb.append(new Character(chars[i])); } + for (int i = 0; i < rightSpaceCnt; i++) sb.append("\\ "); return sb.toString(); } @@ -164,16 +175,20 @@ private static String getUnEscapedValues(char[] chars) { StringBuffer sb = new StringBuffer(); + boolean trailing20h = false; for (int i = 0; i < chars.length; i++) { + trailing20h = false; if (chars[i] != '\\') { sb.append(chars[i]); } else { try { + if (chars[i+1] == ' ') continue; if (!isSpecialChar(chars, i + 1) && !isSpecialChar(chars, i + 2)) { try { sb.append(RelaxedDnParser.hexToUTF8(new String( chars, i + 1, 2))); + if (sb.charAt(sb.length()-1) == ' ') trailing20h = true; i = i + 2; } catch (IOException e) { throw new IllegalArgumentException(Messages.getString("ldap.1A")); @@ -183,6 +198,7 @@ } } } + if (trailing20h && sb.length() > 0 && sb.charAt(sb.length()-1) == ' ') sb = sb.deleteCharAt(sb.length()-1); return sb.toString(); } Index: modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java =================================================================== --- modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java (revision 537153) +++ modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java (working copy) @@ -113,6 +113,7 @@ String attValue; String attType = nextAT(); List atav = new ArrayList(); + String charCopy = new String(chars); while (true) { if (pos == length) { // empty Attribute Value @@ -124,6 +125,13 @@ switch (chars[pos]) { case '"': attValue = quotedAV(); + if (attValue.length() > 0 && attValue.charAt(attValue.length()-1) == ' ') { + int p = pos-1; + while (p>=0 && charCopy.charAt(p)==' ') p--; + if (p >= 3 && charCopy.substring(p-3, p+1).equals("\\20\"")) { + attValue = attValue.substring(0, attValue.length()-1); + } + } atav.add(new AttributeTypeAndValuePair(attType, attValue)); break; case '#': @@ -137,6 +145,13 @@ break; default: attValue = escapedAV(); + if (attValue.length() > 0 && attValue.charAt(attValue.length()-1) == ' ') { + int p = pos-1; + while (p>=0 && charCopy.charAt(p)==' ') p--; + if (p >= 2 && charCopy.substring(p-2, p+1).equals("\\20")) { + attValue = attValue.substring(0, attValue.length()-1); + } + } atav.add(new AttributeTypeAndValuePair(attType, attValue)); }