directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r895544 - in /directory/shared/branches/shared-schema/ldap/src: main/antlr/ main/java/org/apache/directory/shared/ldap/schema/normalizers/ test/java/org/apache/directory/shared/ldap/name/
Date Mon, 04 Jan 2010 03:44:38 GMT
Author: seelmann
Date: Mon Jan  4 03:44:13 2010
New Revision: 895544

URL: http://svn.apache.org/viewvc?rev=895544&view=rev
Log:
o Fixed issues with trailing spaces
o Fixed some tests
o It is no longer necessary to unescape values during DN normalization, the values were already
unescaped by the DN parser. So removed the decode and unescape code from DefaultStringNormalizer.

Modified:
    directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DefaultStringNormalizer.java
    directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java

Modified: directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g?rev=895544&r1=895543&r2=895544&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g Mon Jan
 4 03:44:13 2010
@@ -148,10 +148,8 @@
     }
     static class UpAndNormValue
     {
-        String name = "";
-        String upValue = "";
-        Object normValue = "";
-        String trailingSpaces = "";
+        Object value = "";
+        String rawValue = "";
     }
 }
 
@@ -300,16 +298,16 @@
         {
             try
             {
-                upName += value.name;
+                upName += value.rawValue;
                 AttributeTypeAndValue ava = null;
             
-                if ( value.normValue instanceof String )
+                if ( value.value instanceof String )
                 {
                     ava = new AttributeTypeAndValue(
                         type,
                         type,
-                        new ClientStringValue( value.upValue ), 
-                        new ClientStringValue( (String)value.normValue ),
+                        new ClientStringValue( (String)value.value ), 
+                        new ClientStringValue( (String)value.value ),
                         upName
                     );
                 }
@@ -318,8 +316,8 @@
                     ava = new AttributeTypeAndValue(
                         type,
                         type,
-                        new ClientStringValue( value.upValue ), 
-                        new ClientBinaryValue( (byte[])value.normValue ),
+                        new ClientBinaryValue( (byte[])value.value ), 
+                        new ClientBinaryValue( (byte[])value.value ),
                         upName
                     );
                 }
@@ -416,14 +414,14 @@
     (
         (
             quotestring [value]
-            ( SPACE { value.trailingSpaces += " "; } )*
+            ( SPACE { value.rawValue += " "; } )*
         )
         |
         string [value]
         |
         (
             hexstring [value]
-            ( SPACE { value.trailingSpaces += " "; } )*
+            ( SPACE { value.rawValue += " "; } )*
         )
     )?
     ;
@@ -443,25 +441,23 @@
     }
     :
     (
-        dq1:DQUOTE { value.upValue += dq1.getText(); }
+        dq1:DQUOTE { value.rawValue += dq1.getText(); }
         (
             (
                 s:~(DQUOTE|ESC|ESCESC|ESCSHARP|HEXPAIR) 
                 {
-                    value.upValue += s.getText();
+                    value.rawValue += s.getText();
                     bb.append( StringTools.getBytesUtf8( s.getText() ) ); 
                 }
             )
             |
             bytes = pair[value] { bb.append( bytes ); }
         )*
-        dq2:DQUOTE { value.upValue += dq2.getText(); }
+        dq2:DQUOTE { value.rawValue += dq2.getText(); }
     )
     {
-        // TODO: pair / s
         String string = StringTools.utf8ToString( bb.copyOfUsedBytes() );
-        string = string.replace("\\ ", " ");
-        value.normValue = string;
+        value.value = string;
     }
     ;
 
@@ -484,8 +480,8 @@
     hexValue:HEXVALUE
     {
         // convert to byte[]
-        value.upValue = "#" + hexValue.getText();
-        value.normValue = StringTools.toByteArray( hexValue.getText() ); 
+        value.rawValue = "#" + hexValue.getText();
+        value.value = StringTools.toByteArray( hexValue.getText() ); 
     }
     ;
 
@@ -499,8 +495,6 @@
      * string =   [ ( leadchar / pair ) [ *( stringchar / pair )
      *    ( trailchar / pair ) ] ]
      *
-     * TODO: Trailing SPACE is manually removed. This needs review! 
-     * TODO: ESC SPACE is replaced by a simgle SPACE. This needs review! 
      */ 
 string [UpAndNormValue value]
     {
@@ -514,15 +508,13 @@
         (
             tmp = lutf1 
             { 
-                value.upValue += tmp;
-                value.name += tmp;
+                value.rawValue += tmp;
                 bb.append( StringTools.getBytesUtf8( tmp ) ); 
             }
             |
             tmp = utfmb 
             {
-                value.upValue += tmp;
-                value.name += tmp;
+                value.rawValue += tmp;
                 bb.append( StringTools.getBytesUtf8( tmp ) );
             }
             |
@@ -531,15 +523,13 @@
         ( 
             tmp = sutf1
             {
-                value.upValue += tmp;
-                value.name += tmp;
+                value.rawValue += tmp;
                 bb.append( StringTools.getBytesUtf8( tmp ) ); 
             }
             |
             tmp = utfmb 
             {
-                value.upValue += tmp;
-                value.name += tmp;
+                value.rawValue += tmp;
                 bb.append( StringTools.getBytesUtf8( tmp ) ); 
             }
             |
@@ -551,16 +541,16 @@
         
         // trim trailing space characters manually
         // don't know how to tell antlr that the last char mustn't be a space.
-        while ( string.length() > 0 && value.upValue.length() > 1 
-            && value.upValue.charAt( value.upValue.length() - 1 ) == ' ' 
-            && value.upValue.charAt( value.upValue.length() - 2 ) != '\\' )
+        int rawIndex = value.rawValue.length();
+        while ( string.length() > 0 && rawIndex > 1 
+            && value.rawValue.charAt( rawIndex - 1 ) == ' ' 
+            && value.rawValue.charAt( rawIndex - 2 ) != '\\' )
         {
             string = string.substring( 0, string.length() - 1 );
-            value.upValue = value.upValue.substring( 0, value.upValue.length() - 1 );
-            value.trailingSpaces += " ";
+            rawIndex--;
         }
         
-        value.normValue = string;
+        value.value = string;
     }
     ;
 
@@ -664,7 +654,6 @@
      * <special> ::= "," | "=" | <CR> | "+" | "<" |  ">"
      *           | "#" | ";"
      * 
-     * TODO: The ESC is removed from the norm value. This needs review! 
      */ 
 pair [UpAndNormValue value] returns [byte[] pair]
     {
@@ -675,8 +664,7 @@
     (
         ESCESC 
         { 
-            value.upValue += "\\";
-            value.name += "\\\\";
+            value.rawValue += "\\\\";
             pair = StringTools.getBytesUtf8( "\\" );
         } 
     )
@@ -684,8 +672,7 @@
     (
         ESCSHARP 
         { 
-            value.upValue += "#";
-            value.name += "\\#";
+            value.rawValue += "\\#";
             pair = StringTools.getBytesUtf8( "#" );
         } 
     )
@@ -694,8 +681,7 @@
         ESC
         tmp = special 
         { 
-            value.upValue += tmp;
-            value.name += "\\" + tmp;
+            value.rawValue += "\\" + tmp;
             pair = StringTools.getBytesUtf8( tmp ); 
         }
     )
@@ -703,8 +689,7 @@
     ( 
         hexpair:HEXPAIR 
         { 
-            value.upValue += hexpair.getText();
-            value.name += "\\" + hexpair.getText();
+            value.rawValue += "\\" + hexpair.getText();
             pair = StringTools.toByteArray( hexpair.getText() ); 
         } 
     )
@@ -717,7 +702,6 @@
      * special = escaped / SPACE / SHARP / EQUALS
      * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE
      *
-     * TODO: For space an ESC is manually added. This needs review! 
      */ 
 special returns [String special]
     {

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DefaultStringNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DefaultStringNormalizer.java?rev=895544&r1=895543&r2=895544&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DefaultStringNormalizer.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DefaultStringNormalizer.java
Mon Jan  4 03:44:13 2010
@@ -64,16 +64,6 @@
             return new ClientStringValue( str );
         }
         
-        if ( str.charAt( 0 ) == '#' )
-        {
-            return new ClientStringValue( StringTools.decodeHexString( str ) );
-        }
-        
-        if ( str.indexOf( '\\' ) != -1 )
-        {
-            return new ClientStringValue( StringTools.decodeEscapedHex( str ) );
-        }
-        
         return new ClientStringValue( str );
     }
 
@@ -88,16 +78,6 @@
             return value;
         }
         
-        if ( value.charAt( 0 ) == '#' )
-        {
-            return StringTools.decodeHexString( value );
-        }
-        
-        if ( value.indexOf( '\\' ) != -1 )
-        {
-            return StringTools.decodeEscapedHex( value );
-        }
-        
         return value;
     }
 

Modified: directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?rev=895544&r1=895543&r2=895544&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Mon Jan  4 03:44:13 2010
@@ -3407,7 +3407,7 @@
         assertEquals( " cn = #414243 ", dn3.getRdn().getUpName() );
         AttributeTypeAndValue atav3 = dn3.getRdn().getAtav();
         assertEquals( "cn", atav3.getUpType() );
-        assertEquals( "#414243", atav3.getUpValue().getString() );
+        assertEquals( "ABC", atav3.getUpValue().getString() );
         assertTrue( Arrays.equals( StringTools.getBytesUtf8( "ABC" ),atav3.getNormValue().getBytes()
) );
 
         // antlr parser: 
@@ -3415,7 +3415,7 @@
         assertEquals( " cn = \\41\\42\\43 ", dn4.getRdn().getUpName() );
         AttributeTypeAndValue atav4 = dn4.getRdn().getAtav();
         assertEquals( "cn", atav4.getUpType() );
-        assertEquals( "\\41\\42\\43", atav4.getUpValue().getString() );
+        assertEquals( "ABC", atav4.getUpValue().getString() );
         assertEquals( "ABC", atav4.getNormValue().getString() );
 
         // antlr parser: quotestring with trailing spaces
@@ -3423,7 +3423,7 @@
         assertEquals( " cn = \"ABC\" ", dn5.getRdn().getUpName() );
         AttributeTypeAndValue atav5 = dn5.getRdn().getAtav();
         assertEquals( "cn", atav5.getUpType() );
-        assertEquals( "\"ABC\"", atav5.getUpValue().getString() );
+        assertEquals( "ABC", atav5.getUpValue().getString() );
         assertEquals( "ABC", atav5.getNormValue().getString() );
 
         // fast parser: string value with trailing spaces 
@@ -3613,8 +3613,7 @@
         assertEquals( "ou", atav.getUpType() );
         assertEquals( "Ex+mple", atav.getUpValue().get() );
         
-        // Wrong !!! TODO : fix me
-        assertEquals( "ou  =  Ex\\+mple", atav.getUpName() );
+        assertEquals( "  ou  =  Ex\\+mple ", atav.getUpName() );
     }
 
     



Mime
View raw message