From e3cb7a61df6fd3f219445033a42bccf110b0bbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Wed, 26 Sep 2012 14:52:19 +0200 Subject: [PATCH] Fix the addquotes/removequots functions in libkmime Thanks to Francois Andriot for the patch (cherry picked from commit e09b1f3dbdcdf1f21732552d0e2db11ae3d7bf58) --- libkmime/kmime_util.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/libkmime/kmime_util.cpp b/libkmime/kmime_util.cpp index 542a56bb..72db6208 100644 --- a/libkmime/kmime_util.cpp +++ b/libkmime/kmime_util.cpp @@ -436,29 +436,25 @@ TQCString LFtoCRLF(const TQCString &s) void removeQuots(TQCString &str) { - str.replace(TQRegExp("\\\""), "\""); - str.replace(TQRegExp("\\\\"), "\\"); + // Removes any quote or backslash caracter + str.replace(TQRegExp("[\\\"]"), ""); } void removeQuots(TQString &str) { - str.replace(TQRegExp("\\\""), "\""); - str.replace(TQRegExp("\\\\"), "\\"); + // Removes any quote or backslash caracter + str.replace(TQRegExp("[\\\"]"), ""); } void addQuotes(TQCString &str, bool forceQuotes) { - bool needsQuotes=false; - if ( TQString( str ) .contains( TQRegExp( TQString( "\"|\\\\|=|\\]|\\[|:|;|,|\\.|,|@|<|>|\\)|\\(" ) ) ) ) - needsQuotes = true; - - str.replace(TQRegExp("\\"), "\\\\"); - str.replace(TQRegExp("\""), "\\\""); - - if (needsQuotes || forceQuotes) { - str.insert(0,'\"'); + if ( forceQuotes || TQString(str).contains( TQRegExp( TQString( "\"|\\\\|=|\\]|\\[|:|;|,|\\.|,|@|<|>|\\)|\\(" ) ) ) ) { + // Adds a backslash in front of any existing quote or backslash caracter + str.replace(TQRegExp("([\\\"])"), "\\\\1"); + // Adds quote at beginning and end of thestring + str.insert(0,'"'); str.append("\""); } }