You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2008/07/09 00:12:04 UTC
svn commit: r675000 [1/2] - in /directory:
apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/
shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/
shared/branches/bigbang/ldap/src/main/java/org...
Author: elecharny
Date: Tue Jul 8 15:12:03 2008
New Revision: 675000
URL: http://svn.apache.org/viewvc?rev=675000&view=rev
Log:
Fix for DIRSERVER-1192
Modified:
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java?rev=675000&r1=674999&r2=675000&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java (original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java Tue Jul 8 15:12:03 2008
@@ -502,11 +502,9 @@
Attributes attributes = this.getPersonAttributes( snVal, cnVal );
ctx.createSubcontext( oldRdn, attributes );
- // modify Rdn from cn=Tori Amos to cn=<A Umlaut>\+
- String newCnVal = new String( new byte[]
- { ( byte ) 0xC3, ( byte ) 0x84, '+' }, "UTF-8" );
+ // modify Rdn from cn=Tori Amos to cn=<a Umlaut>\+
String newCnEscapedVal = new String( new byte[]
- { ( byte ) 0xC3, ( byte ) 0x84, '\\', '+' }, "UTF-8" );
+ { ( byte ) 0xC3, ( byte ) 0xA4, '\\', '+' }, "UTF-8" );
ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
String newRdn = "cn=" + newCnEscapedVal;
ctx.rename( oldRdn, newRdn );
@@ -532,7 +530,7 @@
// Check that cn contains the unescaped value
Attribute cn = newCtx.getAttributes( "" ).get( "cn" );
assertEquals( "Number of cn occurences", 1, cn.size() );
- assertTrue( cn.contains( newCnVal ) );
+ assertTrue( cn.contains( "\\C3\\A4\\+" ) );
// Remove entry (use new rdn)
ctx.unbind( newRdn );
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=675000&r1=674999&r2=675000&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Tue Jul 8 15:12:03 2008
@@ -1360,19 +1360,17 @@
*
* @param rdn the RDN we want to normalize. It will contain the resulting normalized RDN
* @param oidNormalizer the normalizer to use for the RDN
- * @param type the attributeType contained into the RDN
* @throws NamingException If something went wrong.
*/
- private static void oidNormalize( Rdn rdn, OidNormalizer oidNormalizer, String type ) throws NamingException
+ private static void oidNormalize( Rdn rdn, OidNormalizer oidNormalizer ) throws NamingException
{
Object upValue = rdn.getUpValue();
String upType = rdn.getUpType();
rdn.clear();
- Object normValue = DefaultStringNormalizer.normalizeString( ( String ) upValue );
-
- rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(), upValue,
- oidNormalizer.getNormalizer().normalize( normValue ) );
+ Object normStringValue = DefaultStringNormalizer.normalizeString( ( String ) upValue );
+ Object normValue = oidNormalizer.getNormalizer().normalize( normStringValue );
+ rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(), upValue, normValue );
}
/**
@@ -1417,7 +1415,7 @@
if ( oidNormalizer != null )
{
- oidNormalize( rdn, oidNormalizer, type );
+ oidNormalize( rdn, oidNormalizer );
}
else
{
@@ -1430,7 +1428,7 @@
if ( oidNormalizer != null )
{
// Ok, just normalize after having removed the 4 first chars
- oidNormalize( rdn, oidNormalizer, type );
+ oidNormalize( rdn, oidNormalizer );
}
else
{
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=675000&r1=674999&r2=675000&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Tue Jul 8 15:12:03 2008
@@ -935,6 +935,28 @@
return ((TreeSet<AttributeTypeAndValue>)atavs).first().getUpValue();
}
}
+
+
+ /**
+ * Return the normalized value, or the first one of we have more than one (the lowest)
+ *
+ * @return The first normalized value of this RDN
+ */
+ public String getNormValue()
+ {
+ switch ( nbAtavs )
+ {
+ case 0:
+ return null;
+
+ case 1:
+ return (String)atav.getNormValue();
+
+ default:
+ return ((TreeSet<AttributeTypeAndValue>)atavs).first().getNormalizedValue();
+ }
+ }
+
/**
* Compares the specified Object with this Rdn for equality. Returns true if
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=675000&r1=674999&r2=675000&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java Tue Jul 8 15:12:03 2008
@@ -473,8 +473,8 @@
if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
{
pos.end++;
+ pos.length = length + 2;
return StringTools.utf8ToString( buffer, length );
- //return StringTools.utf8ToString( bytes, pos.start, pos.length );
}
else
{
@@ -969,13 +969,17 @@
StringTools.trimLeft( dn, pos );
pos.end = pos.start;
+
+ int start2 = pos.start;
if ( ( value = parseAttributeValue( dn, pos ) ) == null )
{
return DNUtils.PARSING_ERROR;
}
- rdn.addAttributeTypeAndValue( type, type, value, value );
+ String upValue = StringTools.utf8ToString( dn, start2, pos.length );
+ rdn.addAttributeTypeAndValue( type, type, upValue, value );
+
rdn.normalize();
pos.start = pos.end;
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=675000&r1=674999&r2=675000&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Tue Jul 8 15:12:03 2008
@@ -276,11 +276,24 @@
}
}
}
+
+
+ /**
+ * Check if the given char is a pair char only
+ * <pairCharOnly> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'
+ *
+ * @param c the char we want to test
+ * @return true if the char is a pair char only
+ */
+ public static boolean isPairCharOnly( char c )
+ {
+ return ( ( ( c | 0x7F ) == 0x7F ) && PAIR_CHAR_ONLY[c & 0x7f] );
+ }
/**
- * Check if the current character is a Pair Char <pairchar> ::= ',' | '=' |
- * '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
+ * Check if the current character is a Pair Char
+ * <pairchar> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
*
* @param bytes The buffer which contains the data
* @param index Current position in the buffer
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=675000&r1=674999&r2=675000&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Tue Jul 8 15:12:03 2008
@@ -3387,11 +3387,14 @@
// create buffer and add everything before start of scan
StringBuffer buf = new StringBuffer();
ByteBuffer bb = new ByteBuffer();
+ boolean escaped = false;
// start scaning until we find an escaped series of bytes
for ( int ii = 0; ii < length; ii++ )
{
- if ( str.charAt( ii ) == '\\' )
+ char c = str.charAt( ii );
+
+ if ( c == '\\' )
{
// we have the start of a hex escape sequence
if ( isHex( str, ii+1 ) && isHex ( str, ii+2 ) )
@@ -3400,18 +3403,44 @@
int advancedBy = collectEscapedHexBytes( bb, str, ii );
ii+=advancedBy-1;
buf.append( StringTools.utf8ToString( bb.buffer(), bb.position() ) );
+ escaped = false;
continue;
}
- else
+ else if ( !escaped )
{
- buf.append( str.charAt( ii ) );
+ // It may be an escaped char ( ' ', '"', '#', '+', ',', ';', '<', '=', '>', '\' )
+ escaped = true;
continue;
}
}
-
- buf.append( str.charAt( ii ) );
+
+ if ( escaped )
+ {
+ if ( DNUtils.isPairCharOnly( c ) )
+ {
+ // It is an escaped char ( ' ', '"', '#', '+', ',', ';', '<', '=', '>', '\' )
+ // Stores it into the buffer without the '\'
+ escaped = false;
+ buf.append( c );
+ continue;
+ }
+ else
+ {
+ throw new InvalidNameException( "The DN must contain valid escaped characters." );
+ }
+ }
+ else
+ {
+ buf.append( str.charAt( ii ) );
+ }
}
+ if ( escaped )
+ {
+ // We should not have a '\' at the end of the string
+ throw new InvalidNameException( "The DN must not ends with a '\\'." );
+ }
+
return buf.toString();
}