[CalendarServer-changes] [12249] CalendarServer/trunk/twistedcaldav/directory
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:24:14 PDT 2014
Revision: 12249
http://trac.calendarserver.org//changeset/12249
Author: sagen at apple.com
Date: 2014-01-06 18:10:02 -0800 (Mon, 06 Jan 2014)
Log Message:
-----------
Remove substring duplicates from search tokens
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py
CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py
Modified: CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py 2014-01-07 00:59:00 UTC (rev 12248)
+++ CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py 2014-01-07 02:10:02 UTC (rev 12249)
@@ -1477,9 +1477,25 @@
"""
filterStr = None
- tokens = [ldapEsc(t) for t in tokens if len(t) > 2]
+
+ # Eliminate any substring duplicates
+ tokenSet = set()
+ for token in tokens:
+ collision = False
+ for existing in tokenSet:
+ if token in existing:
+ collision = True
+ break
+ elif existing in token:
+ tokenSet.remove(existing)
+ break
+ if not collision:
+ tokenSet.add(token)
+
+ tokens = [ldapEsc(t) for t in tokenSet]
if len(tokens) == 0:
return None
+ tokens.sort()
attributes = [
("fullName", "(%s=*%s*)"),
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py 2014-01-07 00:59:00 UTC (rev 12248)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py 2014-01-07 02:10:02 UTC (rev 12249)
@@ -211,6 +211,24 @@
"extra" : "(a=b)",
},
{
+ "tokens" : ["foo", "foo", "oo", "fo", "bar"],
+ "mapping" : {
+ "fullName" : "cn",
+ "emailAddresses" : "mail",
+ },
+ "expected" : "(&(a=b)(|(cn=*bar*)(mail=bar*))(|(cn=*foo*)(mail=foo*)))",
+ "extra" : "(a=b)",
+ },
+ {
+ "tokens" : ["fo", "foo", "foooo", "ooo", "fooo"],
+ "mapping" : {
+ "fullName" : "cn",
+ "emailAddresses" : "mail",
+ },
+ "expected" : "(&(a=b)(|(cn=*foooo*)(mail=foooo*)))",
+ "extra" : "(a=b)",
+ },
+ {
"tokens" : ["foo"],
"mapping" : {
"fullName" : "cn",
@@ -239,7 +257,7 @@
"mapping" : {
"emailAddresses" : "mail",
},
- "expected" : "(&(mail=foo*)(mail=bar*))",
+ "expected" : "(&(mail=bar*)(mail=foo*))",
"extra" : None,
},
{
@@ -248,7 +266,7 @@
"fullName" : "cn",
"emailAddresses" : "mail",
},
- "expected" : "(&(|(cn=*foo*)(mail=foo*))(|(cn=*bar*)(mail=bar*)))",
+ "expected" : "(&(|(cn=*bar*)(mail=bar*))(|(cn=*foo*)(mail=foo*)))",
"extra" : None,
},
{
@@ -257,7 +275,7 @@
"fullName" : "cn",
"emailAddresses" : ["mail", "mailAliases"],
},
- "expected" : "(&(|(cn=*foo*)(mail=foo*)(mailAliases=foo*))(|(cn=*bar*)(mail=bar*)(mailAliases=bar*)))",
+ "expected" : "(&(|(cn=*bar*)(mail=bar*)(mailAliases=bar*))(|(cn=*foo*)(mail=foo*)(mailAliases=foo*)))",
"extra" : None,
},
{
@@ -266,7 +284,7 @@
"fullName" : "cn",
"emailAddresses" : "mail",
},
- "expected" : "(&(|(cn=*foo*)(mail=foo*))(|(cn=*bar*)(mail=bar*))(|(cn=*baz\\28*)(mail=baz\\28*)))",
+ "expected" : "(&(|(cn=*bar*)(mail=bar*))(|(cn=*baz\\28*)(mail=baz\\28*))(|(cn=*foo*)(mail=foo*)))",
"extra" : None,
},
]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/3c86e5d4/attachment.html>
More information about the calendarserver-changes
mailing list