You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/09/22 04:55:18 UTC
svn commit: r290878 - in /directory/apacheds/trunk/core/src:
main/java/org/apache/ldap/server/jndi/ServerDirContext.java
test/org/apache/ldap/server/jndi/SearchContextTest.java
Author: trustin
Date: Wed Sep 21 19:55:13 2005
New Revision: 290878
URL: http://svn.apache.org/viewcvs?rev=290878&view=rev
Log:
Applied a patch by Jacob Barrett for DIREVE-266: ServerDirContext.search() with filter arguments always gets index out of bounds (in two places).
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/SearchContextTest.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java?rev=290878&r1=290877&r2=290878&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java Wed Sep 21 19:55:13 2005
@@ -631,32 +631,44 @@
public NamingEnumeration search( Name name, String filterExpr, Object[] filterArgs, SearchControls cons ) throws NamingException
{
int start;
+ int index;
StringBuffer buf = new StringBuffer( filterExpr );
// Scan until we hit the end of the string buffer
for ( int ii = 0; ii < buf.length(); ii++ )
{
- // Advance until we hit the start of a variable
- while ( '{' != buf.charAt( ii ) )
+ try
{
- ii++;
+ // Advance until we hit the start of a variable
+ while ( ii < buf.length() && '{' != buf.charAt( ii ) )
+ {
+ ii++;
+ }
+
+ // Record start of variable at '{'
+ start = ii;
+
+ // Advance to the end of a variable at '}'
+ while ( '}' != buf.charAt( ii ) )
+ {
+ ii++;
+ }
}
-
- // Record start of variable at '{'
- start = ii;
-
- // Advance to the end of a variable at '}'
- while ( '}' != buf.charAt( ii ) )
+ catch (IndexOutOfBoundsException e)
{
- ii++;
+ // End of filter so done.
+ break;
}
+ // Parse index
+ index = Integer.parseInt(buf.substring(start + 1, ii));
+
/*
* Replace the '{ i }' with the string representation of the value
* held in the filterArgs array at index index.
*/
- buf.replace( start, ii + 1, filterArgs[ii].toString() );
+ buf.replace( start, ii + 1, filterArgs[index].toString() );
}
return search( name, buf.toString(), cons );
Modified: directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/SearchContextTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/SearchContextTest.java?rev=290878&r1=290877&r2=290878&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/SearchContextTest.java (original)
+++ directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/SearchContextTest.java Wed Sep 21 19:55:13 2005
@@ -261,4 +261,33 @@
assertTrue( map.containsKey( "ou=subtest,ou=testing01,ou=system" ) );
}
+
+ public void testSearchFilterArgs() throws NamingException
+ {
+ SearchControls controls = new SearchControls();
+
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+
+ controls.setDerefLinkFlag( false );
+
+ sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, DerefAliasesEnum.NEVERDEREFALIASES.getName() );
+
+ HashMap map = new HashMap();
+
+ NamingEnumeration list = sysRoot.search( "", "(| (ou={0}) (ou={1}))", new Object[] {"testing00", "testing01"}, controls );
+
+ while ( list.hasMore() )
+ {
+ SearchResult result = ( SearchResult ) list.next();
+
+ map.put( result.getName(), result.getAttributes() );
+ }
+
+ assertEquals( "Expected number of results returned was incorrect!", 2, map.size() );
+
+ assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
+
+ assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
+ }
+
}