directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1601267 - in /directory/shared/trunk/ldap/model/src: main/antlr/distinguishedName.g test/java/org/apache/directory/api/ldap/model/name/DnParserTest.java
Date Sun, 08 Jun 2014 22:52:32 GMT
Author: seelmann
Date: Sun Jun  8 22:52:32 2014
New Revision: 1601267

URL: http://svn.apache.org/r1601267
Log:
DIRAPI-185: Allow underscore in attribute name in complex DN parser

Modified:
    directory/shared/trunk/ldap/model/src/main/antlr/distinguishedName.g
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/name/DnParserTest.java

Modified: directory/shared/trunk/ldap/model/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/antlr/distinguishedName.g?rev=1601267&r1=1601266&r2=1601267&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/trunk/ldap/model/src/main/antlr/distinguishedName.g Sun Jun  8 22:52:32
2014
@@ -54,6 +54,7 @@ COMMA : ',' ;
 EQUALS : '=' ;
 PLUS : '+' ;
 HYPHEN : '-' ;
+UNDERSCORE : '_' ;
 DQUOTE : '"' ;
 SEMI : ';' ;
 LANGLE : '<' ;
@@ -101,8 +102,9 @@ UTFMB : '\u0080'..'\uFFFE' ;
  * To avoid nondeterminism the following 
  * rules are excluded. These rules are 
  * explicitly added in the productions.
- *   EQUALS (0x3D) 
- *   HYPHEN (0x2D)  
+ *   EQUALS (0x3D)
+ *   HYPHEN (0x2D)
+ *   UNDERSCORE (0x5F)
  *   DIGIT (0x30-0x39)
  *   ALPHA (0x41-0x5A and 0x61-0x7A)
  */
@@ -114,7 +116,8 @@ LUTF1_REST : 
     '\u003A' |
     '\u003F'..'\u0040' |
     '\u005B' |
-    '\u005D'..'\u0060' | 
+    '\u005D'..'\u005E' | 
+    '\u0060' | 
     '\u007B'..'\u007F' 
     ;
 
@@ -420,6 +423,8 @@ attributeType returns [String attributeT
      * leadkeychar = ALPHA
      * keychar = ALPHA / DIGIT / HYPHEN
      *
+     * We additionally add UNDERSCORE because some servers allow them.
+     *
      */    
 descr returns [String descr]
     {
@@ -433,6 +438,8 @@ descr returns [String descr]
         digit:DIGIT { descr += digit.getText(); }
         |
         hyphen:HYPHEN { descr += hyphen.getText(); }
+        |
+        underscore:UNDERSCORE { descr += underscore.getText(); }
     )*
     ;
 
@@ -622,8 +629,9 @@ string [UpAndNormValue value]
  *
  * The rule LUTF1_REST doesn't contain the following charcters,
  * so we must check them additionally
- *   EQUALS (0x3D) 
- *   HYPHEN (0x2D)  
+ *   EQUALS (0x3D)
+ *   HYPHEN (0x2D)
+ *   UNDERSCORE (0x5F)
  *   DIGIT (0x30-0x39)
  *   ALPHA (0x41-0x5A and 0x61-0x7A)
  */
@@ -638,6 +646,8 @@ lutf1 returns [String lutf1=""]
     |
     hyphen:HYPHEN { lutf1 = hyphen.getText(); }
     |
+    underscore:UNDERSCORE { lutf1 = underscore.getText(); }
+    |
     digit:DIGIT { lutf1 = digit.getText(); }
     |
     alpha:ALPHA { lutf1 = alpha.getText(); }
@@ -652,8 +662,9 @@ lutf1 returns [String lutf1=""]
  *
  * The rule LUTF1_REST doesn't contain the following charcters,
  * so we must check them additionally
- *   EQUALS (0x3D) 
- *   HYPHEN (0x2D)  
+ *   EQUALS (0x3D)
+ *   HYPHEN (0x2D)
+ *   UNDERSCORE (0x5F)
  *   DIGIT (0x30-0x39)
  *   ALPHA (0x41-0x5A and 0x61-0x7A)
  *   SHARP
@@ -670,6 +681,8 @@ sutf1 returns [String sutf1=""]
     |
     hyphen:HYPHEN { sutf1 = hyphen.getText(); }
     |
+    underscore:UNDERSCORE { sutf1 = underscore.getText(); }
+    |
     digit:DIGIT { sutf1 = digit.getText(); }
     |
     alpha:ALPHA { sutf1 = alpha.getText(); }

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/name/DnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/name/DnParserTest.java?rev=1601267&r1=1601266&r2=1601267&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/name/DnParserTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/name/DnParserTest.java
Sun Jun  8 22:52:32 2014
@@ -110,6 +110,30 @@ public class DnParserTest
 
 
     /**
+     * Test an attributeType with '_' (some vendors allow that)
+     */
+    @Test
+    public void testAttributeTypeWithUnderscore() throws LdapException
+    {
+        Dn dn = new Dn( "a_a = b + c_c = d" );
+        assertEquals( "a_a=b+c_c=d", dn.getNormName() );
+        assertEquals( "a_a = b + c_c = d", dn.getName() );
+    }
+
+
+    /**
+     * Test DN with '_' in value, because of special handling in Antlr grammar.
+     */
+    @Test
+    public void testAttributeValueWithUnderscore() throws LdapException
+    {
+        Dn dn = new Dn( "cn=\\#ACL_AD-Projects_Author,ou=Notes_Group,o=Contacts,c=DE" );
+        assertEquals( "cn=\\#ACL_AD-Projects_Author,ou=Notes_Group,o=Contacts,c=DE", dn.getNormName()
);
+        assertEquals( "cn=\\#ACL_AD-Projects_Author,ou=Notes_Group,o=Contacts,c=DE", dn.getName()
);
+    }
+
+
+    /**
      * test a simple Dn with multiple NameComponents : a = b + c = d
      */
     @Test



Mime
View raw message