From 248f23afd6cf6f96c82a12e49d32ff3b00223f87 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Mon, 26 Sep 2011 15:14:10 +0200 Subject: [PATCH] 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 --- offlineimap/imaputil.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/offlineimap/imaputil.py b/offlineimap/imaputil.py index eae9a76..f583312 100644 --- a/offlineimap/imaputil.py +++ b/offlineimap/imaputil.py @@ -34,16 +34,15 @@ def debug(*args): getglobalui().debug('imap', " ".join(msg)) def dequote(string): - """Takes a string which may or may not be quoted and returns it, unquoted. - This function does NOT consider parenthised lists to be quoted. - """ + """Takes string which may or may not be quoted and unquotes it. - if not (string[0] == '"' and string[-1] == '"'): - return string - string = string[1:-1] # Strip off quotes. - string = string.replace('\\"', '"') - string = string.replace('\\\\', '\\') - debug("dequote() returning:", string) + It only considers double quotes. This function does NOT consider + parenthised lists to be quoted. + """ + if string and string.startswith('"') and string.endswith('"'): + string = string[1:-1] # Strip off the surrounding quotes. + string = string.replace('\\"', '"') + string = string.replace('\\\\', '\\') return string def flagsplit(string):