Do not fail calling dequote() with empty string

A report by Dave Abrahams showed that the dequote() function failed when
invoked with an empty string. This fixes the function to be more robust.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-09-26 15:14:10 +02:00
parent 3d00a8bb4a
commit 248f23afd6

View File

@ -34,16 +34,15 @@ def debug(*args):
getglobalui().debug('imap', " ".join(msg)) getglobalui().debug('imap', " ".join(msg))
def dequote(string): def dequote(string):
"""Takes a string which may or may not be quoted and returns it, unquoted. """Takes string which may or may not be quoted and unquotes it.
This function does NOT consider parenthised lists to be quoted.
"""
if not (string[0] == '"' and string[-1] == '"'): It only considers double quotes. This function does NOT consider
return string parenthised lists to be quoted.
string = string[1:-1] # Strip off quotes. """
string = string.replace('\\"', '"') if string and string.startswith('"') and string.endswith('"'):
string = string.replace('\\\\', '\\') string = string[1:-1] # Strip off the surrounding quotes.
debug("dequote() returning:", string) string = string.replace('\\"', '"')
string = string.replace('\\\\', '\\')
return string return string
def flagsplit(string): def flagsplit(string):