harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r794164 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/javax/naming/ main/java/org/apache/harmony/jndi/internal/parser/ test/java/org/apache/harmony/jndi/tests/javax/naming/ test/java/org/apache/harmony/jndi/tests/javax/n...
Date Wed, 15 Jul 2009 07:30:02 GMT
Author: qiuxx
Date: Wed Jul 15 07:30:02 2009
New Revision: 794164

URL: http://svn.apache.org/viewvc?rev=794164&view=rev
Log:
Apply patch for jndi, fix behavior differences while parsing LdapName and CompositeName who
contain some meta characters.

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapNameParser.java
    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/CompositeNameTest.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/javax/naming/CompositeName.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java?rev=794164&r1=794163&r2=794164&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
Wed Jul 15 07:30:02 2009
@@ -308,7 +308,6 @@
      * Format name elements to its string representation.
      */
     private static String formatName(Vector<String> elems) {
-
         // special case: all empty elements
         if (isAllEmptyElements(elems)) {
             StringBuilder buf = new StringBuilder();
@@ -325,17 +324,14 @@
             if (i > 0) {
                 buf.append("/"); //$NON-NLS-1$
             }
-            if (elem.indexOf('/') < 0 && elem.indexOf('\\') < 0
-                    && elem.indexOf('"') < 0) {
+            
+            // Add quotation while elem contains separater char
+            if (elem.indexOf('/') != -1){
+                buf.append("\"");
+                buf.append(elem);
+                buf.append("\"");
+            }else{
                 buf.append(elem);
-            } else {
-                char chars[] = elem.toCharArray();
-                for (char c : chars) {
-                    if (c == '/' || c == '\\' || c == '"') {
-                        buf.append('\\');
-                    }
-                    buf.append(c);
-                }
             }
         }
         return buf.toString();

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapNameParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapNameParser.java?rev=794164&r1=794163&r2=794164&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapNameParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/parser/LdapNameParser.java
Wed Jul 15 07:30:02 2009
@@ -70,9 +70,33 @@
             throw new InvalidNameException("Invalid name: " + s);
         }
 
+        int mark = 0;
+        boolean isInQuote = false;
         for (int i = 0; i < c.length; i++) {
-            if ((c[i] == ',' || c[i] == ';') && c[i - 1] != '\\') {
-
+            if (c[i] == '\"' && i > 0 && c[i-1] != '\\'){
+                if (isInQuote){
+                    isInQuote = false;
+                    continue;
+                }else{
+                    isInQuote = true;
+                    // Record quotation mark's location in case it is a single one
+                    mark = i+1;
+                    continue;
+                }
+            }
+            
+            // Ignore quoted string
+            if (isInQuote) {
+                if (i == c.length -1){
+                    // if the last quotation mark is a single one, ignored it.
+                    // and rescan the chars at the marked location.
+                    i = mark;
+                    isInQuote = false;
+                }
+                continue;
+            }
+            
+            if ((c[i] == ',' || c[i] == ';') && i > 0 && c[i - 1] != '\\')
{
                 String sub = s.substring(from, i);
                 if (sub.equals("")) {
                     throw new InvalidNameException("Invalid name: " + s);

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?rev=794164&r1=794163&r2=794164&view=diff
==============================================================================
--- 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
Wed Jul 15 07:30:02 2009
@@ -44,7 +44,7 @@
      * Constructor
      */
     public LdapRdnParser(String name) {
-        if (name.endsWith("+")) {
+        if (name.endsWith("+") && name.length() > 1 && name.charAt(name.length()-2)
!= '\\') {
             this.name = name.substring(0, name.lastIndexOf('+'));
         } else {
             this.name = name;

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompositeNameTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompositeNameTest.java?rev=794164&r1=794163&r2=794164&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompositeNameTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompositeNameTest.java
Wed Jul 15 07:30:02 2009
@@ -153,6 +153,66 @@
 
         assertEquals("test's", new CompositeName("test's").toString());
         assertEquals("test", new CompositeName("'test'").toString());
+        
+        name = new CompositeName("O=\"s,g");
+        assertEquals("O=\"s,g", name.toString());
+        
+        name = new CompositeName("\"O=/s\"");
+        assertEquals("O=/s", name.get(0));
+
+        name.add("s/s");
+        assertEquals(2, name.size());
+        assertEquals("\"O=/s\"/\"s/s\"", name.toString());
+
+        name.add("ss");
+        assertEquals(3, name.size());
+        assertEquals("\"O=/s\"/\"s/s\"/ss", name.toString());
+
+        name = new CompositeName("\"O=\\s\"");
+        assertEquals("O=\\s", name.toString());
+
+        CompositeName name = new CompositeName("");
+        name.add("abc/abc");
+        assertEquals(1, name.size());
+
+        CompositeName newCompositeName = new CompositeName(name.toString());
+        assertEquals(1, newCompositeName.size());
+        assertEquals(newCompositeName, name);
+        
+        name = new CompositeName("O=\"s,g\"");
+        assertEquals("O=\"s,g\"", name.toString());
+        
+        name = new CompositeName("O=#");
+        assertEquals("O=#", name.toString());
+        
+        name = new CompositeName("O=\\s");
+        assertEquals("O=\\s", name.toString());
+        
+        name = new CompositeName("\"O=\\s\"");
+        assertEquals("O=\\s", name.toString());
+        
+        name = new CompositeName("O=/s");
+        assertEquals("O=/s", name.toString());
+
+        name = new CompositeName("\"O=\"/\"s\"");
+        assertEquals(2,name.size());
+        assertEquals("O=/s", name.toString());
+        
+        name = new CompositeName("");
+        assertEquals(0,name.size());
+        assertEquals("", name.toString());
+        
+        name = new CompositeName("\"\"");
+        assertEquals(1,name.size());
+        assertEquals("/", name.toString());
+        
+        name = new CompositeName("\"\"/\"\"");
+        assertEquals(2,name.size());
+        assertEquals("//", name.toString());
+        
+        name = new CompositeName("\"O=/s\"");
+        assertEquals("\"O=/s\"", name.toString());
+
 	}
 
 	/**

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?rev=794164&r1=794163&r2=794164&view=diff
==============================================================================
--- 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
Wed Jul 15 07:30:02 2009
@@ -621,6 +621,14 @@
             new LdapName(" =b");
             fail("InvalidNameException expected");
         } catch (InvalidNameException e) {}
+
+        LdapName ldapName = new LdapName("cn=a+");
+        assertEquals("cn=a+", ldapName.toString());
+        assertEquals("cn=a", ldapName.getRdns().get(0).toString());
+        
+        ldapName = new LdapName("cn=\\+");
+        assertEquals("cn=\\+", ldapName.toString());
+        assertEquals("cn=\\+", ldapName.getRdns().get(0).toString());
     }
 
     /**
@@ -646,7 +654,132 @@
             fail("InvalidNameException expected");
         } catch (InvalidNameException e) {}
     }
+    
+    /**
+     * <p>
+     * Test method for 'javax.naming.ldap.LdapName(String)'
+     * </p>
+     * <p>
+     * Here we are testing the constructor, this method should accept a
+     * String notice here that here that we are testing the special case
+     * in which the name is quoted and the meta characters in it are ignored.
+     * </p>
+     * <p>
+     * The expected result is an instance of the class.
+     * </p>
+     */
+    public void testLdapNameString054() throws Exception {
+        LdapName ldapName;
+        String stringName;
+        
+        stringName = "dc=apacheorg\"";
+        ldapName = new LdapName(stringName);
+        assertEquals(stringName, ldapName.toString());
+        
+        stringName = "dc=\"apache,org\"";
+        ldapName = new LdapName(stringName);
+        assertEquals(stringName, ldapName.toString());
+        
+        stringName = "dc=\"apache;org\"";
+        ldapName = new LdapName(stringName);
+        assertEquals(stringName, ldapName.toString());
+        
+        stringName = "dc=\"apache\\\";org\"";
+        ldapName = new LdapName(stringName);
+        assertEquals(stringName, ldapName.toString());
+        
+        stringName = "dc=apache\\\"org,O=org";
+        ldapName = new LdapName(stringName);
+        assertEquals(stringName, ldapName.toString());
+        
+        stringName = "\"az=a,O=a\"";
+        try{
+            new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        }catch(InvalidNameException e){
+            //expected
+        }
+        
+        stringName = "dc=apache\\\";org,O=org";
+        try{
+            new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        }catch(InvalidNameException e){
+            //expected
+        }
+        
+        try{
+            new LdapName("dc=apache,org");
+            fail("Should throw InvalidNameException");
+        }catch(InvalidNameException e){
+            //expected
+        }
+        
+        try{
+            new LdapName("dc=apache;org");
+            fail("Should throw InvalidNameException");
+        }catch(InvalidNameException e){
+            //expected
+        }
+        
+        try{
+            new LdapName("dc=\"apache\"harmony\"org\"");
+            fail("Should throw InvalidNameException");
+        }catch(InvalidNameException e){
+            //expected
+        }
+        
+        stringName = "DC=\"Apache,org\",DC=\"Apacheorg\"";
+        String expectedRdnsName = "DC=\"Apache,org\",DC=\"Apacheorg\"";
+        ldapName = new LdapName(stringName);
+        List rdns = ldapName.getRdns();
+        assertEquals(2, rdns.size());
+        assertEquals(expectedRdnsName, ldapName.toString());
+        
+        stringName= "abc=\"DC:O=ab,DC=COM\",cn=apache\"org,O=harmony";
+        new LdapName(stringName);
+
+        try {
+            stringName = "DC=A\"pache,org\",DC=\"Apacheorg\"";
+            ldapName = new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // expected
+        }
+
+        try {
+            stringName = "DC=\"Apache,org,DC=\"Apacheorg\"";
+            ldapName = new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // expected
+        }
 
+        try {
+            stringName = "DC=\"Apache,org,DC=\"Apacheorg";
+            ldapName = new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // expected
+        }
+        
+        try {
+            stringName = "+";
+            ldapName = new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // expected
+        }
+        
+        try {
+            stringName = ";";
+            ldapName = new LdapName(stringName);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // expected
+        }
+    }
+    
     /**
      * <p>
      * Test method for 'javax.naming.ldap.LdapName.LdapName(List<Rdn>)'



Mime
View raw message