--- LdapTemplate.java	Tue Dec 19 14:41:58 2006
+++ zregvart\LdapTemplate.java	Tue Dec 19 19:42:08 2006
@@ -261,16 +261,23 @@
                     // Work out the DN of the matched entry
                     StringBuffer dn = new StringBuffer(searchResult.getName());
 
+                    // append search base and/or context only if the returned result is relative
                     if (searchResult.isRelative()) {
                         if (StringUtils.hasLength(base)) {
-                            dn.append(",");
+                            // for searches that return the search base dn is ""
+                            if (dn.length() > 0) {
+                                dn.append(",");
+                            }
                             dn.append(base);
                         }
 
                         String nameInNamespace = ctx.getNameInNamespace();
 
                         if (StringUtils.hasLength(nameInNamespace)) {
-                            dn.append(",");
+                            // for searches that return the search base dn is ""
+                            if (dn.length() > 0) {
+                                dn.append(",");
+                            }
                             dn.append(nameInNamespace);
                         }
                     }
