From 57b12b944075080a9aa6f6c7a410753314f5b2af Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Thu, 29 Apr 2010 14:01:30 +0100 Subject: [PATCH] Correctly handle \" in quoted strings. (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 | 2 -- imapclient/test/test_IMAPClient.py | 7 ++++++- imapclient/test/test_response_parser.py | 7 +++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/imapclient/response_parser.py b/imapclient/response_parser.py index b164c20..218d7b0 100644 --- a/imapclient/response_parser.py +++ b/imapclient/response_parser.py @@ -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: diff --git a/imapclient/test/test_IMAPClient.py b/imapclient/test/test_IMAPClient.py index 7f2087b..c1546b6 100644 --- a/imapclient/test/test_IMAPClient.py +++ b/imapclient/test/test_IMAPClient.py @@ -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]), []) diff --git a/imapclient/test/test_response_parser.py b/imapclient/test/test_response_parser.py index ebf84fe..4a77267 100644 --- a/imapclient/test/test_response_parser.py +++ b/imapclient/test/test_response_parser.py @@ -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: -- 2.43.0