harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r537277 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/internal/parser/ test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/
Date Fri, 11 May 2007 20:11:33 GMT
Author: tellison
Date: Fri May 11 13:11:31 2007
New Revision: 537277

URL: http://svn.apache.org/viewvc?view=rev&rev=537277
Log:
Apply slightly modified patch HARMONY-3841 ([classlib][jndi] the get(int) method of class
LdapName returns different result from RI)

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/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.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=537277&r1=537276&r2=537277
==============================================================================
--- 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
Fri May 11 13:11:31 2007
@@ -13,7 +13,7 @@
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  *  See the License for the specific language governing permissions and 
  *  limitations under the License. 
- */ 
+ */
 
 package org.apache.harmony.jndi.internal.parser;
 
@@ -69,7 +69,8 @@
         }
 
         attrList = (List) listAll.get(0);
-        for (Iterator<AttributeTypeAndValuePair> iter = attrList.iterator(); iter.hasNext();)
{
+        for (Iterator<AttributeTypeAndValuePair> iter = attrList.iterator(); iter
+                .hasNext();) {
             AttributeTypeAndValuePair element = iter.next();
             list.put(element.getType(), element.getValue());
         }
@@ -110,12 +111,25 @@
 
     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();
     }
 
@@ -123,7 +137,7 @@
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < byteArray.length; i++) {
             sb.append(Integer.toHexString(byteArray[i] >> 4 & 0x0F));
-            sb.append(Integer.toHexString(byteArray[i] & 0x0F)); 
+            sb.append(Integer.toHexString(byteArray[i] & 0x0F));
         }
         return '#' + sb.toString();
     }
@@ -164,25 +178,37 @@
 
     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"));
+                            throw new IllegalArgumentException(Messages
+                                    .getString("ldap.1A"));
                         }
                     }
                 } catch (ArrayIndexOutOfBoundsException e) {
                 }
             }
         }
+        if (trailing20h && sb.length() > 0 && sb.charAt(sb.length() -
1) == ' ') {
+            sb = sb.deleteCharAt(sb.length() - 1);
+        }
         return sb.toString();
     }
 
@@ -199,25 +225,26 @@
                         .substring(2 * i, 2 * i + 2), 16);
             }
         } catch (NumberFormatException e) {
-            throw new IllegalArgumentException(Messages.getString("ldap.17") + val);
+            throw new IllegalArgumentException(Messages.getString("ldap.17")
+                    + val);
         }
         return ret;
     }
 
     private static boolean isSpecialChar(char[] chars, int index) {
         switch (chars[index]) {
-        case '"':
-        case '\\':
-        case ',':
-        case '=':
-        case '+':
-        case '<':
-        case '>':
-        case '#':
-        case ';':
-            return true;
-        default:
-            return false;
+            case '"':
+            case '\\':
+            case ',':
+            case '=':
+            case '+':
+            case '<':
+            case '>':
+            case '#':
+            case ';':
+                return true;
+            default:
+                return false;
         }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java?view=diff&rev=537277&r1=537276&r2=537277
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/RelaxedDnParser.java
Fri May 11 13:11:31 2007
@@ -13,7 +13,7 @@
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  *  See the License for the specific language governing permissions and 
  *  limitations under the License. 
- */ 
+ */
 
 package org.apache.harmony.jndi.internal.parser;
 
@@ -48,6 +48,7 @@
         super(dn);
     }
 
+    @Override
     protected String nextAT() throws IOException {
         int equalIndex = pos;
         try {
@@ -107,12 +108,14 @@
     /**
      * Begin to parse the string given in the constructor
      */
+    @Override
     public List parse() throws IOException {
         List list = new ArrayList();
 
         String attValue;
         String attType = nextAT();
         List atav = new ArrayList();
+        String charCopy = new String(chars);
         while (true) {
             if (pos == length) {
                 // empty Attribute Value
@@ -122,22 +125,48 @@
             }
 
             switch (chars[pos]) {
-            case '"':
-                attValue = quotedAV();
-                atav.add(new AttributeTypeAndValuePair(attType, attValue));
-                break;
-            case '#':
-                attValue = hexAV();
-                atav.add(new AttributeTypeAndValuePair(attType, Rdn
-                        .unescapeValue(attValue)));
-                break;
-            case '+':
-                // empty attribute value
-                atav.add(new AttributeTypeAndValuePair(attType, ""));
-                break;
-            default:
-                attValue = escapedAV();
-                atav.add(new AttributeTypeAndValuePair(attType, attValue));
+                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 '#':
+                    attValue = hexAV();
+                    atav.add(new AttributeTypeAndValuePair(attType, Rdn
+                            .unescapeValue(attValue)));
+                    break;
+                case '+':
+                    // empty attribute value
+                    atav.add(new AttributeTypeAndValuePair(attType, ""));
+                    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));
             }
 
             if (pos >= length) {
@@ -161,27 +190,27 @@
         }
 
         switch (chars[pos]) {
-        case '"':
-            return chars[pos];
-        case '\\':
-            hasQE = true;
-            return hexToUTF8(new String(chars, pos++, 2));
-        case ',':
-        case '=':
-        case '+':
-        case '<':
-        case '>':
-        case '#':
-        case ';':
-        case ' ':
-            // FIXME: escaping is allowed only for leading or trailing space
-            // char
-            return chars[pos];
-        default:
-            // RFC doesn't explicitly say that escaped hex pair is
-            // interpreted as UTF-8 char. It only contains an example of such
-            // DN.
-            return super.getUTF8();
+            case '"':
+                return chars[pos];
+            case '\\':
+                hasQE = true;
+                return hexToUTF8(new String(chars, pos++, 2));
+            case ',':
+            case '=':
+            case '+':
+            case '<':
+            case '>':
+            case '#':
+            case ';':
+            case ' ':
+                // FIXME: escaping is allowed only for leading or trailing space
+                // char
+                return chars[pos];
+            default:
+                // RFC doesn't explicitly say that escaped hex pair is
+                // interpreted as UTF-8 char. It only contains an example of such
+                // DN.
+                return super.getUTF8();
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java?view=diff&rev=537277&r1=537276&r2=537277
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
Fri May 11 13:11:31 2007
@@ -1360,6 +1360,29 @@
 
     /**
      * <p>
+     * Test method for 'javax.naming.ldap.LdapName.get(int)'
+     * </p>
+     * <p>
+     * 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()).
+     * </p>
+     * <p>
+     * The expected result is if the returned string by this method is the
+     * variable wich we create the Name.
+     * </p>
+     */
+    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));
+    }
+    
+    /**
+     * <p>
      * Test method for 'javax.naming.ldap.LdapName.getRdn(int)'
      * </p>
      * <p>



Mime
View raw message