Changeset 142:f5a6a5297de1

Show
Ignore:
Timestamp:
29/04/10 14:01:30 (22 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

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.

Location:
imapclient
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • imapclient/response_parser.py

    r126 r142  
    208208                                literal_len, len(literal_text))) 
    209209        return literal_text 
    210     elif token.startswith('"'): 
    211         return token[1:-1] 
    212210    elif token.isdigit(): 
    213211        return int(token) 
  • imapclient/test/test_IMAPClient.py

    r135 r142  
    9292                                                 r'(\HasNoChildren) "/" "Left\"Right"', 
    9393                                                 r'(\HasNoChildren) "/" "Left\\Right"', 
     94                                                 r'(\HasNoChildren) "/" "\"Left Right\""', 
     95                                                 r'(\HasNoChildren) "/" "\"Left\\Right\""', 
    9496                                                 ]) 
    9597        self.assertEqual(folders, [(['\\HasNoChildren'], '/', 'Test "Folder"'), 
    9698                                   (['\\HasNoChildren'], '/', 'Left\"Right'), 
    97                                    (['\\HasNoChildren'], '/', r'Left\Right')]) 
     99                                   (['\\HasNoChildren'], '/', r'Left\Right'), 
     100                                   (['\\HasNoChildren'], '/', r'"Left Right"'), 
     101                                   (['\\HasNoChildren'], '/', r'"Left\Right"'), 
     102                                   ]) 
    98103 
    99104    def test_empty_response(self): 
  • imapclient/test/test_response_parser.py

    r120 r142  
    133133 
    134134    def test_quoted_specials(self): 
     135        self._test(r'"\"foo bar\""', '"foo bar"') 
    135136        self._test(r'"foo \"bar\""', 'foo "bar"') 
    136137        self._test(r'"foo\\bar"', r'foo\bar') 
     
    157158            to_parse = [to_parse] 
    158159        output = parse_response(to_parse) 
    159         self.assert_( 
    160                 output == expected, 
    161                 format_error(to_parse, output, expected), 
    162             ) 
     160        self.assert_(output == expected, 
     161                     format_error(to_parse, output, expected)) 
    163162 
    164163    def _test_parse_error(self, to_parse, expected_msg):