directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r768522 - in /directory/shared/trunk/ldap/src: main/antlr/distinguishedName.g test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
Date Sat, 25 Apr 2009 12:51:39 GMT
Author: seelmann
Date: Sat Apr 25 12:51:38 2009
New Revision: 768522

URL: http://svn.apache.org/viewvc?rev=768522&view=rev
Log:
Fixed a corner case: the sequence ESC ESC HEX HEX was handled incorrectly by the Antlr based
DN parser

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

Modified: directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g?rev=768522&r1=768521&r2=768522&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g Sat Apr 25 12:51:38 2009
@@ -71,12 +71,14 @@
 protected DIGIT : '0'..'9' ;
 protected ALPHA : 'a'..'z' ;
 
-HEXPAIR_OR_ESC 
+HEXPAIR_OR_ESCESC_OR_ESC 
     : (ESC HEX HEX) => HEXPAIR { $setType(HEXPAIR); }
+    | ESCESC { $setType(ESCESC); }
     | ESC { $setType(ESC); }
     ;
 protected HEXPAIR : ESC! HEX HEX ;
 protected ESC : '\\';
+protected ESCESC : ESC ESC;
 protected HEX: DIGIT | 'a'..'f' ;
 
 HEXVALUE_OR_SHARP
@@ -409,7 +411,7 @@
         DQUOTE
         (
             (
-                s:~(DQUOTE|ESC|HEXPAIR) 
+                s:~(DQUOTE|ESC|ESCESC|HEXPAIR) 
                 {
                     value.upValue += s.getText();
                     bb.append( StringTools.getBytesUtf8( s.getText() ) ); 
@@ -626,12 +628,11 @@
         String tmp;
     }
     :
-    ( 
-        ESC { value.upValue += "\\"; } 
-        esc:ESC 
+    (
+        ESCESC 
         { 
-            value.upValue += "\\";
-            pair = StringTools.getBytesUtf8( esc.getText() );
+            value.upValue += "\\\\";
+            pair = StringTools.getBytesUtf8( "\\" );
         } 
     )
     |

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java?rev=768522&r1=768521&r2=768522&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
Sat Apr 25 12:51:38 2009
@@ -255,6 +255,23 @@
         LdapDN dn = ( LdapDN ) dnParser.parse( "a = quoted \\\"value" );
         assertEquals( "a=quoted \\\"value", dn.toString() );
         assertEquals( "a = quoted \\\"value", dn.getUpName() );
+        
+        dn = ( LdapDN ) dnParser.parse( "cn=Mackie \\\"The Knife\\\" Messer" );
+        assertEquals( "cn=Mackie \\\"The Knife\\\" Messer", dn.toString() );
+        assertEquals( "cn=Mackie \\\"The Knife\\\" Messer", dn.getUpName() );
+    }
+
+
+    /**
+     * Tests a corner case of the parser because the sequence "\DC" is also a valid hex pair
+     */
+    @Test
+    public void testLdapDNBackslashInAttributeValue() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a = AC\\\\DC" );
+        assertEquals( "a=AC\\\\DC", dn.toString() );
+        assertEquals( "a = AC\\\\DC", dn.getUpName() );
     }
 
 



Mime
View raw message