Skip to content

Commit 0c658a8

Browse files
Sebastien PonceSebastien Ponce
Sebastien Ponce
authored and
Sebastien Ponce
committed
Make sure to escape properly items in csv files
1 parent 1b19a34 commit 0c658a8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

fstimer/printer/printcsv.py

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def file_extension(self):
4242
containing data from this printer'''
4343
return 'csv'
4444

45+
def escape(self, word):
46+
'''returns an escaped version of the value'''
47+
if type(word) == str and word.find(',') >= 0:
48+
return '"' + word.replace('"', '\\"') + '"'
49+
else:
50+
return word
51+
4552
def scratch_table_header(self):
4653
'''Returns the header of the printout for scratch results'''
4754
return 'Place,' + ','.join(self.fields) + '\n'

fstimer/printer/printer.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ def cat_table_footer(self, category):
7373
@type category: string
7474
@param category: name of the category handled by the table'''
7575
return ''
76-
76+
77+
def escape(self, word):
78+
'''returns an escaped version of the value, if needed'''
79+
return word
80+
7781
def common_entry(self, row):
78-
return self.row_delim.join(row)
82+
return self.row_delim.join(map(self.escape, row))
7983

8084
def scratch_entry(self, row, category=None):
8185
'''Returns the printout of the entry of a given runner

0 commit comments

Comments
 (0)