]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Don't automatically quote search criteria when provided as a single string
authorMenno Smits <menno@freshfoo.com>
Tue, 25 Aug 2015 00:18:33 +0000 (12:18 +1200)
committerMenno Smits <menno@freshfoo.com>
Tue, 25 Aug 2015 00:18:33 +0000 (12:18 +1200)
It's up to the caller to handle quoting if criteria are provided this way.

imapclient/imapclient.py
imapclient/test/test_util_functions.py

index b7ad304609d3de3900622a24a3bd4ece99fbc404..17cd10c0d6654dcc82499245472c33706c10db5a 100644 (file)
@@ -1217,10 +1217,10 @@ def seq_to_parenstr_upper(items):
 def _normalise_search_criteria(criteria, charset=None):
     if not criteria:
         raise ValueError('no criteria specified')
-    if isinstance(criteria, (text_type, binary_type)):
-        criteria = [criteria]
     if not charset:
         charset = 'us-ascii'
+    if isinstance(criteria, (text_type, binary_type)):
+        return [to_bytes(criteria, charset)]
     return [_maybe_quote(to_bytes(item, charset)) for item in criteria]
 
 def _normalise_sort_criteria(criteria, charset=None):
index 57be556dcdb8cf8ea031f03dd8b1976a045e74b7..a0606d861ada2e9da9d07e6729b96d8d4dc390bf 100644 (file)
@@ -118,6 +118,18 @@ class Test_normalise_search_criteria(unittest.TestCase):
     def check(self, criteria, charset, expected):
         self.assertEqual(_normalise_search_criteria(criteria, charset), expected)
 
+    def test_list(self):
+        self.check(['FOO', '\u263a'], 'utf-8', [b'FOO', b'\xe2\x98\xba'])
+
+    def test_tuple(self):
+        self.check(('FOO', 'BAR'), None, [b'FOO', b'BAR'])
+
+    def test_mixed_list(self):
+        self.check(['FOO', b'BAR'], None, [b'FOO', b'BAR'])
+
+    def test_quoting(self):
+        self.check(['foo bar'], None, [b'"foo bar"'])
+
     def test_unicode(self):
         self.check('Foo', None, [b'Foo'])
 
@@ -128,16 +140,11 @@ class Test_normalise_search_criteria(unittest.TestCase):
         self.check('\u263a', 'UTF-8', [b'\xe2\x98\xba'])
 
     def test_binary_with_charset(self):
+        # charset is unused when criteria is binary.
         self.check(b'FOO', 'UTF-9', [b'FOO'])
 
-    def test_tuple(self):
-        self.check(('FOO', 'BAR'), None, [b'FOO', b'BAR'])
-
-    def test_list(self):
-        self.check(['FOO', 'BAR'], None, [b'FOO', b'BAR'])
-
-    def test_mixed_list(self):
-        self.check(['FOO', b'BAR'], None, [b'FOO', b'BAR'])
+    def test_no_quoting_when_criteria_given_as_string(self):
+        self.check('foo bar', None, [b'foo bar'])
 
     def test_None(self):
         self.assertRaises(ValueError, _normalise_search_criteria, None, None)