Author: seelmann
Date: Tue Apr 14 07:15:07 2009
New Revision: 764690
URL: http://svn.apache.org/viewvc?rev=764690&view=rev
Log:
DIRSERVER-1247: Applied patch from Norval Hope with some modifications
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterCloneTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastLdapDnParserTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java Tue Apr 14 07:15:07 2009
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.List;
-import javax.naming.InvalidNameException;
import javax.naming.NamingException;
import org.apache.directory.server.schema.registries.Registries;
@@ -42,9 +41,7 @@
import org.apache.directory.shared.ldap.filter.SubstringNode;
import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.util.ByteBuffer;
import org.apache.directory.shared.ldap.util.StringTools;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -114,112 +111,6 @@
return ( ( ( c | 0x7F ) == 0x7F ) && FILTER_CHAR[c & 0x7f] );
}
- /**
- * Decodes sequences of escaped hex within an attribute's value into
- * a UTF-8 String. The hex is decoded inline and the complete decoded
- * String is returned.
- *
- * @param str the string containing hex escapes
- * @return the decoded string
- */
- private static final String decodeEscapedHex( String str ) throws InvalidNameException
- {
- // create buffer and add everything before start of scan
- StringBuffer buf = new StringBuffer();
- ByteBuffer bb = new ByteBuffer();
- boolean escaped = false;
-
- // start scanning until we find an escaped series of bytes
- for ( int ii = 0; ii < str.length(); ii++ )
- {
- char c = str.charAt( ii );
-
- if ( c == '\\' )
- {
- // we have the start of a hex escape sequence
- if ( StringTools.isHex( str, ii+1 ) && StringTools.isHex ( str, ii+2 ) )
- {
- bb.clear();
- int advancedBy = StringTools.collectEscapedHexBytes( bb, str, ii );
- ii+=advancedBy-1;
- buf.append( StringTools.utf8ToString( bb.buffer(), bb.position() ) );
- escaped = false;
- continue;
- }
- else if ( !escaped )
- {
- // It may be an escaped char ( '\0', '(', ')', '*', '\' )
- escaped = true;
- continue;
- }
- }
-
-
- if ( escaped )
- {
- if ( isFilterChar( c ) )
- {
- // It is an escaped char ( '\0', '(', ')', '*', '\' )
- // Stores it into the buffer without the '\'
- escaped = false;
- buf.append( c );
- continue;
- }
- else
- {
- throw new InvalidNameException( "The value 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 value must not ends with a '\\'." );
-
- // TODO: We have a weird behaviour:
- // - If a request (cn=\5C) comes over the wire the '\5C' is already decoded to a '\'.
- // - If we use the embedded LdapContext it is not decoded here.
- // This is just a hack to make it working.
- buf.append( '\\' );
- }
-
- return buf.toString();
- }
-
-
- /**
- * Un-escape the escaped chars in the value
- */
- private void unescapeValue( Value<?> value )
- {
- if ( !value.isBinary() )
- {
- String valStr = (String)value.getNormalizedValue();
-
- if ( StringTools.isEmpty( valStr ) )
- {
- return;
- }
-
- try
- {
- String newStr= decodeEscapedHex( valStr );
- ((ClientStringValue)value).set( newStr );
- return;
- }
- catch ( InvalidNameException ine )
- {
- value.set( null );
- return;
- }
- }
- }
-
/**
*
@@ -256,15 +147,11 @@
{
normalized = new ClientStringValue( ( String ) ncn.normalizeByName( attribute, StringTools
.utf8ToString( ( byte[] ) value.get() ) ) );
-
- unescapeValue( normalized );
}
else
{
normalized = new ClientStringValue( ( String ) ncn.normalizeByName( attribute, ( String ) value
.get() ) );
-
- unescapeValue( normalized );
}
}
else
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java Tue Apr 14 07:15:07 2009
@@ -135,6 +135,69 @@
/**
+ * Handles the escaping of special characters in LDAP search filter assertion values using the
+ * <valueencoding> rule as described in
+ * <a href="http://www.ietf.org/rfc/rfc4515.txt">RFC 4515</a>. Needed so that
+ * {@link ExprNode#printToBuffer(StringBuffer)} results in a valid filter string that can be parsed
+ * again (as a way of cloning filters).
+ *
+ * @param value Right hand side of "attrId=value" assertion occurring in an LDAP search filter.
+ * @return Escaped version of <code>value</code>
+ */
+ protected static String escapeFilterValue( Object value )
+ {
+ StringBuilder sb = null;
+ String val;
+
+ if ( !( value instanceof String ) )
+ {
+ return value.toString();
+ }
+
+ val = ( String ) value;
+ for ( int i = 0; i < val.length(); i++ )
+ {
+ char ch = val.charAt( i );
+ String replace = null;
+
+ switch ( ch )
+ {
+ case '*':
+ replace = "\\2a";
+ break;
+ case '(':
+ replace = "\\28";
+ break;
+ case ')':
+ replace = "\\29";
+ break;
+ case '\\':
+ replace = "\\5c";
+ break;
+ case '\0':
+ replace = "\\00";
+ break;
+ }
+ if ( replace != null )
+ {
+ if ( sb == null )
+ {
+ sb = new StringBuilder( val.length() * 2 );
+ sb.append( val.substring( 0, i ) );
+ }
+ sb.append( replace );
+ }
+ else if ( sb != null )
+ {
+ sb.append( ch );
+ }
+ }
+
+ return ( sb == null ? val : sb.toString() );
+ }
+
+
+ /**
* @see Object#hashCode()
* @return the instance's hash code
*/
@@ -155,7 +218,7 @@
return h;
}
-
+
/**
* @see org.apache.directory.shared.ldap.filter.ExprNode#get(java.lang.Object)
@@ -198,7 +261,6 @@
return annotations;
}
-
/**
* Default implementation for this method : just throw an exception.
*
@@ -254,5 +316,5 @@
{
return "";
}
- }
+ }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java Tue Apr 14 07:15:07 2009
@@ -58,7 +58,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( "~=" ).append( value );
+ buf.append( '(' ).append( getAttribute() ).append( "~=" ).append( getValueEscaped() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java Tue Apr 14 07:15:07 2009
@@ -74,7 +74,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( "=" ).append( value );
+ buf.append( '(' ).append( getAttribute() ).append( "=" ).append( getValueEscaped() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Tue Apr 14 07:15:07 2009
@@ -22,6 +22,8 @@
import java.text.ParseException;
+import javax.naming.InvalidNameException;
+
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.Position;
@@ -81,7 +83,7 @@
pos.start++;
// Get the assertionValue
- node.setValue( parseAssertionValue( filter, pos ) );
+ node.setValue( parseAssertionValue( filter, pos, true ) );
return node;
}
@@ -96,7 +98,7 @@
pos.start += 2;
// Get the assertionValue
- node.setValue( parseAssertionValue( filter, pos ) );
+ node.setValue( parseAssertionValue( filter, pos, true ) );
return node;
}
@@ -143,7 +145,7 @@
pos.start++;
// Get the assertionValue
- node.setValue( parseAssertionValue( filter, pos ) );
+ node.setValue( parseAssertionValue( filter, pos, true ) );
return node;
}
@@ -158,7 +160,7 @@
pos.start += 2;
// Get the assertionValue
- node.setValue( parseAssertionValue( filter, pos ) );
+ node.setValue( parseAssertionValue( filter, pos, true ) );
return node;
}
@@ -209,9 +211,10 @@
* HEX = '0'-'9' / 'A'-'F' / 'a'-'f'
* unicodeSubset = %x01-27 / %x2B-5B / %x5D-FFFF
*/
- private static String parseAssertionValue( String filter, Position pos ) throws ParseException
+ private static String parseAssertionValue( String filter, Position pos, boolean preserveEscapedChars ) throws ParseException
{
int start = pos.start;
+ boolean foundHex = false;
char c = StringTools.charAt( filter, pos.start );
@@ -240,6 +243,7 @@
if ( StringTools.isHex( filter, pos.start ) )
{
pos.start++;
+ foundHex = true;
}
else
{
@@ -249,12 +253,30 @@
else
{
// not a valid char, so let's get out
- return filter.substring( start, pos.start );
+ break;
}
}
while ( ( c = StringTools.charAt( filter, pos.start ) ) != '\0' );
- return filter.substring( start, pos.start );
+ String ret = filter.substring( start, pos.start );
+ if ( !preserveEscapedChars && foundHex )
+ {
+ try
+ {
+ ret = StringTools.decodeEscapedHex( ret );
+ }
+ catch ( InvalidNameException e )
+ {
+ throw new ParseException( "Unable to decode escaped hex sequences: '" + ret + "': " + e, pos.start );
+ }
+ }
+ return ret;
+ }
+
+
+ private static String parseAssertionValue( String filter, Position pos ) throws ParseException
+ {
+ return parseAssertionValue( filter, pos, false );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java Tue Apr 14 07:15:07 2009
@@ -60,7 +60,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( ">=" ).append( value );
+ buf.append( '(' ).append( getAttribute() ).append( ">=" ).append( getValueEscaped() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java Tue Apr 14 07:15:07 2009
@@ -60,7 +60,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( "<=" ).append( value );
+ buf.append( '(' ).append( getAttribute() ).append( "<=" ).append( getValueEscaped() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java Tue Apr 14 07:15:07 2009
@@ -82,6 +82,20 @@
return value;
}
+ /**
+ * @return representation of value, escaped for use in a filter if required
+ */
+ protected Object getValueEscaped()
+ {
+ Object valueEscaped = value.get();
+
+ if ( valueEscaped instanceof String )
+ {
+ valueEscaped = AbstractExprNode.escapeFilterValue( valueEscaped );
+ }
+ return valueEscaped;
+ }
+
/**
* Sets the value of this node.
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java Tue Apr 14 07:15:07 2009
@@ -285,7 +285,7 @@
if ( null != initialPattern )
{
- buf.append( initialPattern ).append( '*' );
+ buf.append( AbstractExprNode.escapeFilterValue(initialPattern) ).append( '*' );
}
else
{
@@ -296,14 +296,14 @@
{
for ( String any:anyPattern )
{
- buf.append( any );
+ buf.append( AbstractExprNode.escapeFilterValue(any) );
buf.append( '*' );
}
}
if ( null != finalPattern )
{
- buf.append( finalPattern );
+ buf.append( AbstractExprNode.escapeFilterValue(finalPattern) );
}
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java Tue Apr 14 07:15:07 2009
@@ -631,12 +631,7 @@
// for 99.99% of all DN (blind bet, of course ...)
for ( char c:chars )
{
- if ( ( c < 0) || ( c > 128 ) )
- {
- escaped = true;
- break;
- }
- else if ( DN_ESCAPED_CHARS[ c ] )
+ if ( ( c >= 0 ) && ( c < DN_ESCAPED_CHARS.length ) && DN_ESCAPED_CHARS[ c ] )
{
escaped = true;
break;
@@ -649,20 +644,8 @@
for ( int i = 0; i < valueLength; i++ )
{
char c = chars[i];
-
- if ( ( c < 0) || ( c > 128 ) )
- {
- // For chars which are not ASCII, use their hexa value prefixed by an '\'
- byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
-
- for ( byte b:bb )
- {
- sb.append( '\\' ).
- append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
- append( StringTools.dumpHex( b ) );
- }
- }
- else if ( DN_ESCAPED_CHARS[ c ] )
+
+ if ( ( c >= 0 ) && ( c < DN_ESCAPED_CHARS.length ) && DN_ESCAPED_CHARS[ c ] )
{
// Some chars need to be escaped even if they are US ASCII
// Just prefix them with a '\'
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Tue Apr 14 07:15:07 2009
@@ -3473,7 +3473,7 @@
for ( int ii = index; ii < str.length(); ii += 3, advanceBy += 3 )
{
// we have the start of a hex escape sequence
- if ( isHex( str, ii+1 ) && isHex ( str, ii+2 ) )
+ if ( ( str.charAt( ii ) == '\\' ) && isHex( str, ii+1 ) && isHex ( str, ii+2 ) )
{
int bite = ( StringTools.HEX_VALUE[str.charAt( ii+1 )] << 4 ) +
StringTools.HEX_VALUE[str.charAt( ii+2 )];
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterCloneTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterCloneTest.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterCloneTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterCloneTest.java Tue Apr 14 07:15:07 2009
@@ -115,7 +115,7 @@
// just check that it doesnt throw for now
node = (SimpleNode)node.clone();
assertEquals( "ou;lang-de", node.getAttribute() );
- assertEquals( "\\23\\42asdl fkajsd", node.getValue().get() );
+ assertEquals( "#Basdl fkajsd", node.getValue().get() );
}
@@ -127,7 +127,7 @@
// just check that it doesnt throw for now
node = (SimpleNode)node.clone();
assertEquals( "ou;lang-de;version-124", node.getAttribute() );
- assertEquals( "\\23\\42asdl fkajsd", node.getValue().get() );
+ assertEquals( "#Basdl fkajsd", node.getValue().get() );
}
@@ -139,7 +139,7 @@
// just check that it doesnt throw for now
node = (SimpleNode)node.clone();
assertEquals( "1.3.4.2;lang-de;version-124", node.getAttribute() );
- assertEquals( "\\23\\42asdl fkajsd", node.getValue().get() );
+ assertEquals( "#Basdl fkajsd", node.getValue().get() );
}
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java Tue Apr 14 07:15:07 2009
@@ -20,6 +20,7 @@
package org.apache.directory.shared.ldap.filter;
+import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import org.apache.directory.shared.ldap.filter.BranchNode;
@@ -82,55 +83,74 @@
@Test
public void testItemFilter() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(ou~=people)" );
+ String str = "(ou~=people)";
+
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertEquals( "people", node.getValue().get() );
assertTrue( node instanceof ApproximateNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testAndFilter() throws ParseException
{
- BranchNode node = ( BranchNode ) FilterParser.parse( "(&(ou~=people)(age>=30))" );
+ String str = "(&(ou~=people)(age>=30))";
+ BranchNode node = ( BranchNode ) FilterParser.parse( str );
assertEquals( 2, node.getChildren().size() );
assertTrue( node instanceof AndNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testAndFilterOneChildOnly() throws ParseException
{
- BranchNode node = ( BranchNode ) FilterParser.parse( "(&(ou~=people))" );
+ String str = "(&(ou~=people))";
+ BranchNode node = ( BranchNode ) FilterParser.parse( str );
assertEquals( 1, node.getChildren().size() );
assertTrue( node instanceof AndNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testOrFilter() throws ParseException
{
- BranchNode node = ( BranchNode ) FilterParser.parse( "(|(ou~=people)(age>=30))" );
+ String str = "(|(ou~=people)(age>=30))";
+ BranchNode node = ( BranchNode ) FilterParser.parse( str );
assertEquals( 2, node.getChildren().size() );
assertTrue( node instanceof OrNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testOrFilterOneChildOnly() throws ParseException
{
- BranchNode node = ( BranchNode ) FilterParser.parse( "(|(age>=30))" );
+ String str = "(|(age>=30))";
+ BranchNode node = ( BranchNode ) FilterParser.parse( str );
assertEquals( 1, node.getChildren().size() );
assertTrue( node instanceof OrNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testNotFilter() throws ParseException
{
- BranchNode node = ( BranchNode ) FilterParser.parse( "(!(&(ou~= people)(age>=30)))" );
+ String str = "(!(&(ou~= people)(age>=30)))";
+ BranchNode node = ( BranchNode ) FilterParser.parse( str );
assertEquals( 1, node.getChildren().size() );
assertTrue( node instanceof NotNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@@ -138,9 +158,12 @@
@Test
public void testOptionAndEscapesFilter() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(ou;lang-de>=\\23\\42asdl fkajsd)" );
+ String str = "(ou;lang-de>=\\23\\42asdl fkajsd)"; // \23 = '#'
+ SimpleNode node = ( SimpleNode ) FilterParser.parse( str );
assertEquals( "ou;lang-de", node.getAttribute() );
- assertEquals( "\\23\\42asdl fkajsd", node.getValue().get() );
+ assertEquals( "#Basdl fkajsd", node.getValue().get() );
+ String str2 = node.toString();
+ assertEquals( "(ou;lang-de>=#Basdl fkajsd)", str2 );
}
@@ -148,9 +171,12 @@
@Test
public void testOptionsAndEscapesFilter() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(ou;lang-de;version-124>=\\23\\42asdl fkajsd)" );
+ String str = "(ou;lang-de;version-124>=\\23\\42asdl fkajsd)";
+ SimpleNode node = ( SimpleNode ) FilterParser.parse( str );
assertEquals( "ou;lang-de;version-124", node.getAttribute() );
- assertEquals( "\\23\\42asdl fkajsd", node.getValue().get() );
+ assertEquals( "#Basdl fkajsd", node.getValue().get() );
+ String str2 = node.toString();
+ assertEquals( "(ou;lang-de;version-124>=#Basdl fkajsd)", str2 );
}
@@ -158,27 +184,36 @@
@Test
public void testNumericoidOptionsAndEscapesFilter() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(1.3.4.2;lang-de;version-124>=\\23\\42asdl fkajsd)" );
+ String str = "(1.3.4.2;lang-de;version-124>=\\23\\42afdl fkajsd)";
+ SimpleNode node = ( SimpleNode ) FilterParser.parse( str );
assertEquals( "1.3.4.2;lang-de;version-124", node.getAttribute() );
- assertEquals( "\\23\\42asdl fkajsd", node.getValue().get() );
+ assertEquals( "#Bafdl fkajsd", node.getValue().get() );
+ String str2 = node.toString();
+ assertEquals( "(1.3.4.2;lang-de;version-124>=#Bafdl fkajsd)", str2 );
}
@Test
public void testPresentFilter() throws ParseException
{
- PresenceNode node = ( PresenceNode ) FilterParser.parse( "(ou=*)" );
+ String str = "(ou=*)";
+ PresenceNode node = ( PresenceNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof PresenceNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testNumericoidPresentFilter() throws ParseException
{
- PresenceNode node = ( PresenceNode ) FilterParser.parse( "(1.2.3.4=*)" );
+ String str = "(1.2.3.4=*)";
+ PresenceNode node = ( PresenceNode ) FilterParser.parse( str );
assertEquals( "1.2.3.4", node.getAttribute() );
assertTrue( node instanceof PresenceNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@@ -186,10 +221,13 @@
@Test
public void testEqualsFilter() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(ou=people)" );
+ String str = "(ou=people)";
+ SimpleNode node = ( SimpleNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertEquals( "people", node.getValue().get() );
assertTrue( node instanceof EqualityNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@@ -214,17 +252,21 @@
@Test
public void testEqualsWithForwardSlashFilter() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(ou=people/in/my/company)" );
+ String str = "(ou=people/in/my/company)";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertEquals( "people/in/my/company", node.getValue().get() );
assertTrue( node instanceof EqualityNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testExtensibleFilterForm1() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(ou:dn:stupidMatch:=dummyAssertion\\23\\ac)" );
+ String str = "(ou:dn:stupidMatch:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "stupidMatch", node.getMatchingRuleId() );
@@ -236,7 +278,8 @@
@Test
public void testExtensibleFilterForm1WithNumericOid() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(1.2.3.4:dn:1.3434.23.2:=dummyAssertion\\23\\ac)" );
+ String str = "(1.2.3.4:dn:1.3434.23.2:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( "1.2.3.4", node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "1.3434.23.2", node.getMatchingRuleId() );
@@ -248,7 +291,8 @@
@Test
public void testExtensibleFilterForm1NoDnAttr() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(ou:stupidMatch:=dummyAssertion\\23\\ac)" );
+ String str = "(ou:stupidMatch:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "stupidMatch", node.getMatchingRuleId() );
@@ -275,7 +319,8 @@
@Test
public void testExtensibleFilterForm1NoAttrNoMatchingRule() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(ou:=dummyAssertion\\23\\ac)" );
+ String str = "(ou:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( null, node.getMatchingRuleId() );
@@ -287,7 +332,8 @@
@Test
public void testExtensibleFilterForm2() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(:dn:stupidMatch:=dummyAssertion\\23\\ac)" );
+ String str = "(:dn:stupidMatch:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( null, node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "stupidMatch", node.getMatchingRuleId() );
@@ -314,7 +360,8 @@
@Test
public void testExtensibleFilterForm2WithNumericOid() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(:dn:1.3434.23.2:=dummyAssertion\\23\\ac)" );
+ String str = "(:dn:1.3434.23.2:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( null, node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "1.3434.23.2", node.getMatchingRuleId() );
@@ -326,7 +373,8 @@
@Test
public void testExtensibleFilterForm2NoDnAttr() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(:stupidMatch:=dummyAssertion\\23\\ac)" );
+ String str = "(:stupidMatch:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( null, node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "stupidMatch", node.getMatchingRuleId() );
@@ -338,7 +386,8 @@
@Test
public void testExtensibleFilterForm2NoDnAttrWithNumericOidNoAttr() throws ParseException
{
- ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( "(:1.3434.23.2:=dummyAssertion\\23\\ac)" );
+ String str = "(:1.3434.23.2:=dummyAssertion\\23\\ac)";
+ ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
assertEquals( null, node.getAttribute() );
assertEquals( "dummyAssertion\\23\\ac", StringTools.utf8ToString( node.getValue() ) );
assertEquals( "1.3434.23.2", node.getMatchingRuleId() );
@@ -464,7 +513,8 @@
@Test
public void testSubstringNoAnyNoFinal() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=foo*)" );
+ String str = "(ou=foo*)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -472,13 +522,16 @@
assertFalse( node.getAny().contains( "" ) );
assertEquals( "foo", node.getInitial() );
assertEquals( null, node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringNoAny() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=foo*bar)" );
+ String str = "(ou=foo*bar)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -486,13 +539,16 @@
assertFalse( node.getAny().contains( "" ) );
assertEquals( "foo", node.getInitial() );
assertEquals( "bar", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringNoAnyNoIni() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=*bar)" );
+ String str = "(ou=*bar)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -500,13 +556,16 @@
assertFalse( node.getAny().contains( "" ) );
assertEquals( null, node.getInitial() );
assertEquals( "bar", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringOneAny() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=foo*guy*bar)" );
+ String str = "(ou=foo*guy*bar)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -515,13 +574,16 @@
assertTrue( node.getAny().contains( "guy" ) );
assertEquals( "foo", node.getInitial() );
assertEquals( "bar", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringManyAny() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=a*b*c*d*e*f)" );
+ String str = "(ou=a*b*c*d*e*f)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -533,13 +595,16 @@
assertTrue( node.getAny().contains( "e" ) );
assertEquals( "a", node.getInitial() );
assertEquals( "f", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringNoIniManyAny() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=*b*c*d*e*f)" );
+ String str = "(ou=*b*c*d*e*f)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -551,13 +616,16 @@
assertTrue( node.getAny().contains( "d" ) );
assertEquals( null, node.getInitial() );
assertEquals( "f", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringManyAnyNoFinal() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=a*b*c*d*e*)" );
+ String str = "(ou=a*b*c*d*e*)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -569,13 +637,16 @@
assertTrue( node.getAny().contains( "d" ) );
assertEquals( "a", node.getInitial() );
assertEquals( null, node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringNoIniManyAnyNoFinal() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=*b*c*d*e*)" );
+ String str = "(ou=*b*c*d*e*)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -587,13 +658,16 @@
assertTrue( node.getAny().contains( "d" ) );
assertEquals( null, node.getInitial() );
assertEquals( null, node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringNoAnyDoubleSpaceStar() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=foo* *bar)" );
+ String str = "(ou=foo* *bar)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -602,13 +676,16 @@
assertTrue( node.getAny().contains( " " ) );
assertEquals( "foo", node.getInitial() );
assertEquals( "bar", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@Test
public void testSubstringAnyDoubleSpaceStar() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=foo* a *bar)" );
+ String str = "(ou=foo* a *bar)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -617,6 +694,8 @@
assertTrue( node.getAny().contains( " a " ) );
assertEquals( "foo", node.getInitial() );
assertEquals( "bar", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
@@ -628,7 +707,8 @@
@Test
public void testSubstringStarAnyStar() throws ParseException
{
- SubstringNode node = ( SubstringNode ) FilterParser.parse( "(ou=*foo*)" );
+ String str = "(ou=*foo*)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
assertEquals( "ou", node.getAttribute() );
assertTrue( node instanceof SubstringNode );
@@ -636,20 +716,170 @@
assertTrue( node.getAny().contains( "foo" ) );
assertNull( node.getInitial() );
assertNull( node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
}
-
-
+
+
@SuppressWarnings("unchecked")
@Test
- public void testEqualsFilterNullValue() throws ParseException
+ public void testTwoByteUTF8Raw() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(ou=)" );
- assertEquals( "ou", node.getAttribute() );
- assertEquals( "", node.getValue().get() );
- assertTrue( node instanceof EqualityNode );
+ byte[] bytes =
+ { ( byte ) 0xC2, ( byte ) 0xA2 }; // unicode U+00A2: cents sign
+
+ try
+ {
+ String s = new String( bytes, "UTF-8" );
+ String str = "(cn=" + s + ")";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
+
+ assertEquals( "cn", node.getAttribute() );
+ String val = node.getValue().get();
+ assertEquals( "a2", Integer.toHexString( ( int ) val.charAt( 0 ) ) ); // char is U+00A2
+ String str2 = node.toString();
+ assertEquals( str, str2 );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ fail();
+ }
}
-
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testTwoByteUTF8Escaped() throws ParseException
+ {
+ byte[] bytes =
+ { ( byte ) 0xC2, ( byte ) 0xA2 }; // unicode U+00A2: cents sign
+
+ try
+ {
+ String str = "(cn=\\c2\\a2)";
+ String s = new String( bytes, "UTF-8" );
+ String strOut = "(cn=" + s + ")";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
+
+ assertEquals( "cn", node.getAttribute() );
+ String val = ( String ) node.getValue().get();
+ assertEquals( "a2", Integer.toHexString( ( int ) val.charAt( 0 ) ) ); // char is U+00A2
+ String str2 = node.toString();
+ assertEquals( strOut, str2 );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ fail();
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testThreeByteUTF8Raw() throws ParseException
+ {
+ byte[] bytes =
+ { ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA0 }; // unicode U+2260: "not equal to" sign in decimal signed bytes is -30, -119, -96
+
+ try
+ {
+ String s = new String( bytes, "UTF-8" );
+ String str = "(cn=" + s + ")";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
+
+ assertEquals( "cn", node.getAttribute() );
+ String val = node.getValue().get();
+ assertEquals( "2260", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ fail();
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testThreeByteUTF8Escaped() throws ParseException
+ {
+ byte[] bytes =
+ { ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA0 }; // unicode U+2260: "not equal to" sign in decimal signed bytes is -30, -119, -96
+
+ try
+ {
+ String str = "(cn=\\e2\\89\\a0aa)";
+ String s = new String( bytes, "UTF-8" );
+ String strOut = "(cn=" + s + "aa)";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
+
+ assertEquals( "cn", node.getAttribute() );
+ String val = ( String ) node.getValue().get();
+ assertEquals( "2260", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+ String str2 = node.toString();
+ assertEquals( strOut, str2 );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ fail();
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testThreeByteJapaneseUTF8Raw() throws ParseException
+ {
+ byte[] bytes =
+ { ( byte ) 0xE3, ( byte ) 0x81, ( byte ) 0x99 }; // unicode U+3059: Japanese 'T' with squiggle on down-stroke.
+
+ try
+ {
+ String s = new String( bytes, "UTF-8" );
+ String str = "(cn=" + s + ")";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
+
+ assertEquals( "cn", node.getAttribute() );
+ String val = node.getValue().get();
+ assertEquals( "3059", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ fail();
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testThreeByteJapaneseUTF8Escaped() throws ParseException
+ {
+ byte[] bytes =
+ { ( byte ) 0xE3, ( byte ) 0x81, ( byte ) 0x99 }; // unicode U+3059: Japanese 'T' with squiggle on down-stroke.
+
+ try
+ {
+ String str = "(cn=\\e3\\81\\99)";
+ String s = new String( bytes, "UTF-8" );
+ String strOut = "(cn=" + s + ")";
+
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
+ assertEquals( "cn", node.getAttribute() );
+ String val = node.getValue().get();
+ assertEquals( "3059", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+ String str2 = node.toString();
+ assertEquals( strOut, str2 );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ fail();
+ }
+ }
+
+
/**
* test a filter with a # in value
*/
@@ -657,13 +887,15 @@
@Test
public void testEqualsFilterWithPoundInValue() throws ParseException
{
- SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( "(uid=#f1)" );
+ String str = "(uid=#f1)";
+ SimpleNode<String> node = ( SimpleNode<String> ) FilterParser.parse( str );
assertEquals( "uid", node.getAttribute() );
assertEquals( "#f1", node.getValue().get() );
assertTrue( node instanceof EqualityNode );
+ assertEquals( str, node.toString() );
}
-
+
/**
* Test that special and non allowed chars into an assertionValue are not
* accepted. ((cf DIRSERVER-1196)
@@ -674,7 +906,7 @@
{
try
{
- FilterParser.parse("(memberOf=1.2.840.113556.1.4.1301=$#@&*()==,2.5.4.11=local,2.5.4.11=users,2.5.4.11=readimanager)");
+ FilterParser.parse( "(memberOf=1.2.840.113556.1.4.1301=$#@&*()==,2.5.4.11=local,2.5.4.11=users,2.5.4.11=readimanager)" );
fail();
}
catch ( ParseException pe )
@@ -721,18 +953,75 @@
assertTrue( rightNode instanceof SubstringNode );
assertEquals( "nisNetGroupTriple", ((SubstringNode)rightNode).getAttribute() );
- assertEquals( "\\28", ((SubstringNode)rightNode).getInitial() );
+ assertEquals( "(", ((SubstringNode)rightNode).getInitial() );
assertEquals( 1, ((SubstringNode)rightNode).getAny().size() );
assertEquals( ",acc1,", ((SubstringNode)rightNode).getAny().get( 0 ) );
- assertEquals( "\\29", ((SubstringNode)rightNode).getFinal() );
+ assertEquals( ")", ((SubstringNode)rightNode).getFinal() );
}
catch ( ParseException pe )
{
assertTrue( true );
}
}
-
-
+
+
+ @Test
+ public void testObjectClassAndFilterWithSpaces() throws ParseException
+ {
+ String str = "(&(objectClass=person)(objectClass=organizationalUnit))";
+ BranchNode node = ( BranchNode ) FilterParser.parse( str );
+ assertEquals( 2, node.getChildren().size() );
+ assertTrue( node instanceof AndNode );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testQuotedChars() throws ParseException
+ {
+ String str = "(cn='~%\\28'$'\\5c)"; // note \28='(' and \5c='\'
+ ExprNode node = FilterParser.parse( str );
+ assertTrue( node instanceof EqualityNode );
+ assertEquals( "'~%('$'\\", ( ( EqualityNode<String> ) node ).getValue().get() );
+ String str2 = node.toString();
+ assertEquals( str, str2 );
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testQuotedCharsCase() throws ParseException
+ {
+ String str = "(cn='~%\\28'$'\\5Cac)"; // note \28='(' and \5c='\'
+ ExprNode node = FilterParser.parse( str );
+ assertTrue( node instanceof EqualityNode );
+ assertEquals( "'~%('$'\\ac", ( ( EqualityNode<String> ) node ).getValue().get() );
+ String str2 = node.toString();
+ assertEquals( str.toUpperCase(), str2.toUpperCase() );
+ }
+
+
+ @Test
+ public void testQuotedSubstringManyAny() throws ParseException
+ {
+ String str = "(ou=\\5C*\\00*\\3D*\\2Abb)";
+ SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
+ assertEquals( "ou", node.getAttribute() );
+ assertTrue( node instanceof SubstringNode );
+
+ assertEquals( 2, node.getAny().size() );
+ assertFalse( node.getAny().contains( "" ) );
+ assertEquals( "\\", node.getInitial() );
+ assertTrue( node.getAny().contains( "\0" ) );
+ assertTrue( node.getAny().contains( "=" ) );
+ assertEquals( "*bb", node.getFinal() );
+ String str2 = node.toString();
+ assertEquals( "(ou=\\5c*\\00*=*\\2abb)", str2 );
+ }
+
+
/*
@Test
public void testPerf() throws ParseException
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastLdapDnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastLdapDnParserTest.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastLdapDnParserTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastLdapDnParserTest.java Tue Apr 14 07:15:07 2009
@@ -392,7 +392,7 @@
LdapDN name = ( LdapDN ) dnParser.parse( dn );
Assert.assertEquals( dn, name.getUpName() );
- Assert.assertEquals( "cn=Emmanuel L\\C3\\A9charny", name.toString() );
+ Assert.assertEquals( "cn=Emmanuel L\u00e9charny", name.toString() );
}
@@ -405,7 +405,7 @@
LdapDN name = ( LdapDN ) dnParser.parse( dn );
Assert.assertEquals( dn, name.getUpName() );
- Assert.assertEquals( "c=E\\C3\\A9c", name.toString() );
+ Assert.assertEquals( "c=E\u00e9c", name.toString() );
}
@@ -691,7 +691,7 @@
NameParser parser = FastLdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", result );
+ assertEquals( "cn=J\u00e9r\u00f4me", result );
}
@@ -706,7 +706,7 @@
NameParser parser = FastLdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", result );
+ assertEquals( "cn=\u00C4\u00D6\u00DC\u00DF\u00E4\u00F6\u00FC", result );
}
@@ -721,7 +721,7 @@
NameParser parser = FastLdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", result );
+ assertEquals( "cn=\u0130\u0131\u015E\u015F\u00D6\u00F6\u00DC\u00FC\u011E\u011F", result );
}
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java Tue Apr 14 07:15:07 2009
@@ -320,11 +320,10 @@
@Test
public void testLdapDNPairCharAttributeValue() throws InvalidNameException
{
-
LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
- assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
+ assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u010D", dn.toString() );
assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
}
@@ -338,7 +337,7 @@
LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
- assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
+ assertEquals( "sn=Lu\u010Di\u0107", dn.toString() );
assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
}
@@ -1525,7 +1524,6 @@
@Test
public void testStringParser() throws Exception
{
-
String dn = StringTools.utf8ToString( new byte[]
{ 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
@@ -1533,7 +1531,7 @@
Name name = LdapDnParser.getNameParser().parse( dn );
assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
- assertEquals( "cn=Emmanuel L\\C3\\A9charny", name.toString() );
+ assertEquals( "cn=Emmanuel L\u00E9charny", name.toString() );
}
@@ -2371,7 +2369,7 @@
Name name = new LdapDN( cn );
- assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
+ assertEquals( "cn=J\u00e9r\u00f4me", name.toString() );
}
@@ -2385,7 +2383,7 @@
Name name = new LdapDN( cn );
- assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
+ assertEquals( "cn=\u00C4\u00D6\u00DC\u00DF\u00E4\u00F6\u00FC", name.toString() );
}
@@ -2400,8 +2398,7 @@
Name name = new LdapDN( cn );
- assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
- .toString() );
+ assertEquals( "cn=\u0130\u0131\u015E\u015F\u00D6\u00F6\u00DC\u00FC\u011E\u011F", name.toString() );
}
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=764690&r1=764689&r2=764690&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 Tue Apr 14 07:15:07 2009
@@ -200,8 +200,12 @@
{
NameParser dnParser = LdapDnParser.getNameParser();
LdapDN dn = ( LdapDN ) dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9" );
- assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", dn.toString() );
+ assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00e9", dn.toString() );
assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9", dn.getUpName() );
+
+ dn = ( LdapDN ) dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\u00e9" );
+ assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00e9", dn.toString() );
+ assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\u00e9", dn.getUpName() );
}
@@ -281,7 +285,7 @@
LdapDN name = ( LdapDN ) dnParser.parse( dn );
assertEquals( dn, name.getUpName() );
- assertEquals( "cn=Emmanuel L\\C3\\A9charny", name.toString() );
+ assertEquals( "cn=Emmanuel L\u00e9charny", name.toString() );
}
@@ -295,7 +299,7 @@
LdapDN name = ( LdapDN ) dnParser.parse( dn );
assertEquals( dn, name.getUpName() );
- assertEquals( "c=E\\C3\\A9c", name.toString() );
+ assertEquals( "c=E\u00e9c", name.toString() );
}
@@ -547,8 +551,7 @@
NameParser parser = LdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", result );
-
+ assertEquals( "cn=J\u00e9r\u00f4me", result.toString() );
}
@@ -563,7 +566,7 @@
NameParser parser = LdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", result );
+ assertEquals( "cn=\u00C4\u00D6\u00DC\u00DF\u00E4\u00F6\u00FC", result.toString() );
}
@@ -579,8 +582,7 @@
NameParser parser = LdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", result );
-
+ assertEquals( "cn=\u0130\u0131\u015E\u015F\u00D6\u00F6\u00DC\u00FC\u011E\u011F", result.toString() );
}
@@ -593,7 +595,7 @@
NameParser parser = LdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=\\C3\\84\\+", result );
+ assertEquals( "cn=\u00c4\\+", result );
}
@@ -605,7 +607,7 @@
NameParser parser = LdapDnParser.getNameParser();
String result = parser.parse( cn ).toString();
- assertEquals( "cn=\\C3\\84\\+", result );
+ assertEquals( "cn=\u00c4\\+", result );
}
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=764690&r1=764689&r2=764690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java Tue Apr 14 07:15:07 2009
@@ -219,7 +219,7 @@
String rdn = StringTools.utf8ToString( new byte[]
{ 'a', '=', '\\', ',', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\', ';', '\\', '\\', '\\', '"', '\\',
'C', '3', '\\', 'A', '9' } );
- assertEquals( rdn, new Rdn( "a = \\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9" ).toString() );
+ assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00E9", new Rdn( rdn ).toString() );
}
|