[CalendarServer-changes] [12252] twext/trunk/twext/who/opendirectory

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:19:13 PDT 2014


Revision: 12252
          http://trac.calendarserver.org//changeset/12252
Author:   wsanchez at apple.com
Date:     2014-01-06 19:20:09 -0800 (Mon, 06 Jan 2014)
Log Message:
-----------
Add quoting

Modified Paths:
--------------
    twext/trunk/twext/who/opendirectory/_service.py
    twext/trunk/twext/who/opendirectory/test/test_service.py

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2014-01-07 02:40:28 UTC (rev 12251)
+++ twext/trunk/twext/who/opendirectory/_service.py	2014-01-07 03:20:09 UTC (rev 12252)
@@ -251,8 +251,8 @@
         else:
             notOp = u""
 
-        if MatchFlags.caseInsensitive in flags:
-            raise NotImplementedError("Need to handle caseInsensitive")
+        # if MatchFlags.caseInsensitive not in flags:
+        #     raise NotImplementedError("Need to handle case sensitive")
 
         if expression.fieldName is self.fieldName.uid:
             odAttr = ODAttribute.guid
@@ -268,7 +268,27 @@
 
         value = unicode(value)
 
-        # FIXME: Shouldn't the value be quoted somehow?
+        # Do some quoting
+        for character, replacement in (
+            (u"\\", u"\\5C"),  # Must be first.
+            (u"/", u"\\2F"),
+
+            (u"(", u"\\28"),
+            (u")", u"\\29"),
+            (u"*", u"\\2A"),
+
+            (u"<", u"\\3C"),
+            (u"=", u"\\3D"),
+            (u">", u"\\3E"),
+            (u"~", u"\\7E"),
+
+            (u"&", u"\\26"),
+            (u"|", u"\\7C"),
+
+            (u"\0", u"\\00")
+        ):
+            value = value.replace(character, replacement)
+
         return matchType.queryString.format(
             notOp=notOp, attribute=odAttr.value, value=value
         )

Modified: twext/trunk/twext/who/opendirectory/test/test_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/test/test_service.py	2014-01-07 02:40:28 UTC (rev 12251)
+++ twext/trunk/twext/who/opendirectory/test/test_service.py	2014-01-07 03:20:09 UTC (rev 12252)
@@ -38,7 +38,6 @@
         Match expressions with each match type produces the correct
         operator=value string.
         """
-
         service = DirectoryService()
 
         for matchType, expected in (
@@ -68,7 +67,6 @@
         """
         Match expression with the C{NOT} flag adds the C{!} operator.
         """
-
         service = DirectoryService()
 
         expression = MatchExpression(
@@ -89,7 +87,6 @@
         Match expression with the C{caseInsensitive} flag adds the C{??????}
         operator.
         """
-
         service = DirectoryService()
 
         expression = MatchExpression(
@@ -109,6 +106,29 @@
     )
 
 
+    def test_queryStringFromMatchExpression_match_quoting(self):
+        """
+        Special characters are quoted properly.
+        """
+        service = DirectoryService()
+
+        expression = MatchExpression(
+            service.fieldName.fullNames,
+            u"\\xyzzy: a/b/(c)* ~~ >=< ~~ &| \0!!"
+        )
+        queryString = service._queryStringFromExpression(expression)
+        self.assertEquals(
+            queryString,
+            u"({attribute}={expected})".format(
+                attribute=ODAttribute.fullName.value,
+                expected=(
+                    u"\\5Cxyzzy: a\\2Fb\\2F\\28c\\29\\2A "
+                    "\\7E\\7E \\3E\\3D\\3C \\7E\\7E \\26\\7C \\00!!"
+                )
+            )
+        )
+
+
     def test_queryStringFromExpression(self):
         service = DirectoryService()
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/f99764c1/attachment.html>


More information about the calendarserver-changes mailing list