]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Correctly handle \" in quoted strings.
authorMenno Smits <menno@freshfoo.com>
Thu, 29 Apr 2010 13:01:30 +0000 (14:01 +0100)
committerMenno Smits <menno@freshfoo.com>
Thu, 29 Apr 2010 13:01:30 +0000 (14:01 +0100)
(As reported in comments of #28)

It turns out these were being handled twice causing them to be
incorrectly removed if a string started with a double quote.

Extended tests to cover more cases around escaped double quotes. Prior
to this the test weren't covering enough cases.

imapclient/response_parser.py
imapclient/test/test_IMAPClient.py
imapclient/test/test_response_parser.py

index b164c20453baeb042b7664dffd7122d97db6fdeb..218d7b07afb4d66f047e6344e4704b8f3bf7df94 100644 (file)
@@ -207,8 +207,6 @@ def atom(src, token):
             raise ParseError('Expecting literal of size %d, got %d' % (
                                 literal_len, len(literal_text)))
         return literal_text
-    elif token.startswith('"'):
-        return token[1:-1]
     elif token.isdigit():
         return int(token)
     else:
index 7f2087b7635aafb8935db7d24d9721693701fb18..c1546b643e811e905f57a4b9d50b1445e7d9ca36 100644 (file)
@@ -91,10 +91,15 @@ class TestListFolders(IMAPClientTest):
         folders = self.client._proc_folder_list([r'(\HasNoChildren) "/" "Test \"Folder\""',
                                                  r'(\HasNoChildren) "/" "Left\"Right"',
                                                  r'(\HasNoChildren) "/" "Left\\Right"',
+                                                 r'(\HasNoChildren) "/" "\"Left Right\""',
+                                                 r'(\HasNoChildren) "/" "\"Left\\Right\""',
                                                  ])
         self.assertEqual(folders, [(['\\HasNoChildren'], '/', 'Test "Folder"'),
                                    (['\\HasNoChildren'], '/', 'Left\"Right'),
-                                   (['\\HasNoChildren'], '/', r'Left\Right')])
+                                   (['\\HasNoChildren'], '/', r'Left\Right'),
+                                   (['\\HasNoChildren'], '/', r'"Left Right"'),
+                                   (['\\HasNoChildren'], '/', r'"Left\Right"'),
+                                   ])
 
     def test_empty_response(self):
         self.assertEqual(self.client._proc_folder_list([None]), [])
index ebf84fe87ea666f328f6a101838a0eefd59b0f51..4a7726711932be414f4ce38e6f618861a9f951cd 100644 (file)
@@ -132,6 +132,7 @@ class TestParseResponse(unittest.TestCase):
 
 
     def test_quoted_specials(self):
+        self._test(r'"\"foo bar\""', '"foo bar"')
         self._test(r'"foo \"bar\""', 'foo "bar"')
         self._test(r'"foo\\bar"', r'foo\bar')
 
@@ -156,10 +157,8 @@ class TestParseResponse(unittest.TestCase):
         if not isinstance(to_parse, list):
             to_parse = [to_parse]
         output = parse_response(to_parse)
-        self.assert_(
-                output == expected,
-                format_error(to_parse, output, expected),
-            )
+        self.assert_(output == expected,
+                     format_error(to_parse, output, expected))
 
     def _test_parse_error(self, to_parse, expected_msg):
         try: