@@ -41,16 +41,18 @@ def format(self, msg, exporter_context):
41
41
# msg.date.hour, msg.date.minute, msg.id, "RE_ID=%s " % re_id if re_id else "",
42
42
# name, self._py_encode_basestring(content))
43
43
44
- # Check if name contains ','. If it does surround the name with quotes.
45
- if name and name .find ("," ) != - 1 :
46
- if name .startswith ("\" " ) and name .endswith ("\" " ):
47
- name = '"' + name + '"'
44
+ name , isNameModified = self ._py_encode_basestring (name )
45
+
46
+ # Check if name contains ',' or there were other special chars.
47
+ # If it does surround the name with quotes.
48
+ if name and (name .find ("," ) != - 1 or isNameModified ):
49
+ name = '"' + name + '"'
48
50
49
51
msg_dump_str = "," .join ([str (msg .id ),
50
52
msg .date .isoformat (),
51
53
name ,
52
54
str (re_id ),
53
- '"' + str (self ._py_encode_basestring (content )) + '"' ])
55
+ '"' + str (self ._py_encode_basestring (content )[ 0 ] ) + '"' ])
54
56
return msg_dump_str
55
57
56
58
def begin_final_file (self , resulting_file , exporter_context ):
@@ -65,7 +67,10 @@ def begin_final_file(self, resulting_file, exporter_context):
65
67
def _py_encode_basestring (self , s ):
66
68
"""Return a JSON representation of a Python string"""
67
69
if not s :
68
- return s
70
+ return s , False
71
+ isAnyCharReplaced = False
69
72
def replace (match ):
73
+ nonlocal isAnyCharReplaced
74
+ isAnyCharReplaced = True
70
75
return self .ESCAPE_DICT [match .group (0 )]
71
- return self .ESCAPE .sub (replace , s )
76
+ return str ( self .ESCAPE .sub (replace , s )), isAnyCharReplaced
0 commit comments