@Test
public void testSubstringSearchWithEscapedCharsInFilter() throws Exception
{
LdapContext ctx = ( LdapContext ) getWiredContext( getLdapServer() ).lookup( BASE );
Attributes attrs = new BasicAttributes( "objectClass", "inetOrgPerson", true );
attrs.get( "objectClass" ).add( "organizationalPerson" );
attrs.get( "objectClass" ).add( "person" );
attrs.put( "givenName", "Jim" );
attrs.put( "sn", "Bean" );
attrs.put( "cn", "jimbean" );
attrs.put( "description", "(sex*pis\\tols)" );
ctx.createSubcontext( "cn=jimbean", attrs );
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
controls.setReturningAttributes( new String[]
{ "cn" } );
String[] filters = new String[]
{ "(description=*\\28*)", "(description=*\\29*)", "(description=*\\2A*)", "(description=*\\5C*)" };
for ( String filter : filters )
{
NamingEnumeration<SearchResult> res = ctx.search( "", filter, controls );
assertTrue( res.hasMore() );
SearchResult result = res.next();
assertNotNull( result );
attrs = result.getAttributes();
assertEquals( 1, attrs.size() );
assertNotNull( attrs.get( "cn" ) );
assertEquals( 1, attrs.get( "cn" ).size() );
assertEquals( "jimbean", attrs.get( "cn" ).get() );
assertFalse( res.hasMore() );
}
}