harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548905 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/RdnTest.java
Date Wed, 20 Jun 2007 03:13:40 GMT
Author: tonywu
Date: Tue Jun 19 20:13:39 2007
New Revision: 548905

URL: http://svn.apache.org/viewvc?view=rev&rev=548905
Log:
Apply patch HARMONY-4229 ([classlib][jndi] Class Rdn.unescapeValue() has some failures)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/RdnTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java?view=diff&rev=548905&r1=548904&r2=548905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapRdnParser.java
Tue Jun 19 20:13:39 2007
@@ -156,7 +156,27 @@
         } else if (val.startsWith("#")) {
             return getByteFromHexString(val);
         } else {
-            char[] chars = new String(val.trim()).toCharArray();
+            String tmpVal = val.trim();
+            if (tmpVal.length() > 0 && tmpVal.charAt(0) == '\"'
+                    && tmpVal.charAt(tmpVal.length() - 1) == '\"') {
+                if (tmpVal.length() == 1) {
+                    val = "";
+                } else {
+                    val = tmpVal.substring(1, tmpVal.length() - 1);
+                }
+            }
+            char[] chars;
+            int pos = val.length() - 1;
+            boolean trailingSpace = false;
+            while (pos >= 0 && val.charAt(pos) == ' ') {
+                trailingSpace = true;
+                pos--;
+            }
+            if (pos >= 0 && val.charAt(pos) == '\\' && trailingSpace)
{
+                chars = (new String(val.trim()) + " ").toCharArray();
+            } else {
+                chars = new String(val.trim()).toCharArray();
+            }
             return getUnEscapedValues(chars);
         }
 
@@ -188,6 +208,11 @@
                     if (chars[i + 1] == ' ') {
                         continue;
                     }
+                    if (chars[i + 1] == '\\') {
+                        sb.append('\\');
+                        i = i + 1;
+                        continue;
+                    }
                     if (!isSpecialChar(chars, i + 1)
                             && !isSpecialChar(chars, i + 2)) {
                         try {
@@ -203,6 +228,7 @@
                         }
                     }
                 } catch (ArrayIndexOutOfBoundsException e) {
+                    sb.append(chars[i]);
                 }
             }
         }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/RdnTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/RdnTest.java?view=diff&rev=548905&r1=548904&r2=548905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/RdnTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/RdnTest.java
Tue Jun 19 20:13:39 2007
@@ -2104,6 +2104,34 @@
         } catch (IllegalArgumentException e) {}
     }
 
+    /**
+     * <p>
+     * Test method for 'javax.naming.ldap.Rdn.unescapeValue(String)'
+     * </p>
+     * <p>
+     * Here we are testing if a given attribute value string formated, returns
+     * the unformated value. In this case we are testing the special character
+     * "#" in the form "#GOFJMOII".
+     * </p>
+     * <p>
+     * The expected result is an exception.
+     * </p>
+     */
+    public void testUnescapeValue011() {
+        try {
+            assertEquals("te st  ", Rdn.unescapeValue("te st \\  "));
+            assertEquals("te\\st", Rdn.unescapeValue("te\\\\st"));
+            assertEquals("test", Rdn.unescapeValue("\"test\""));
+            assertEquals("\"test", Rdn.unescapeValue("\"test"));
+            assertEquals("\"te\"st", Rdn.unescapeValue("\"te\"st"));
+            assertEquals("te\"st", Rdn.unescapeValue("\"te\"st\""));
+            assertEquals("test", Rdn.unescapeValue(" \"test\"  "));
+            assertEquals("\"test\"  ", Rdn.unescapeValue(" \"test\" \\ "));
+            assertEquals("te1st\\", Rdn.unescapeValue(" \"te\\31st\\\" "));
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
     public void testSerializationCompatibility() throws Exception{
         Rdn object = new Rdn("t=\\20\\ te\\ s\\20t\\20\\20 + t2 = test1\\20\\ ");
         SerializationTest.verifyGolden(this, object);



Mime
View raw message