Skip to content

Commit fcea8ec

Browse files
author
David Noble
committed
DVPL-4290: Custom search commands add quotes around multi-valued field values
Fix: Added _to_string method which converts + bool ⇒ 't' | 'f' + str ⇒ str + number ⇒ str(number) + anything_else ⇒ repr(anything_else) Signed-off-by: David Noble <dnoble@splunk.com>
1 parent c7eeebe commit fcea8ec

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

splunklib/searchcommands/csv/dict_writer.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# under the License.
1414

1515
from __future__ import absolute_import
16+
17+
from numbers import Number
1618
import csv
1719

1820

@@ -59,13 +61,24 @@ def _encode_list(self, value):
5961
if len(value) == 1:
6062
return value[0], None
6163
multi_value = ';'.join(
62-
['$' + repr(item).replace('$', '$$') + '$' for item in value])
64+
['$' + DictWriter._to_string(item).replace('$', '$$') + '$' for item
65+
in value])
6366
value = self._mv_delimiter.join([repr(item) for item in value])
6467
return value, multi_value
6568

6669
def _header_written(self):
6770
return self._fieldnames is not None
6871

72+
@staticmethod
73+
def _to_string(item):
74+
if isinstance(item, bool):
75+
return 't' if item else 'f'
76+
if isinstance(item, str):
77+
return item
78+
if isinstance(item, Number):
79+
return str(item)
80+
return repr(item)
81+
6982
def _writeheader(self, record):
7083
if self.fieldnames is None:
7184
self.fieldnames = sorted(record.keys())

0 commit comments

Comments
 (0)