Skip to content

Commit 3231ef6

Browse files
committed
fix for s #1 - sanitize csv values
1 parent f3a0bc5 commit 3231ef6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arches/app/search/search_export.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import logging
2323
from io import StringIO
2424
from io import BytesIO
25+
import re
2526
from django.contrib.gis.geos import GeometryCollection, GEOSGeometry
2627
from django.core.files import File
2728
from django.utils.translation import ugettext as _
@@ -341,7 +342,7 @@ def to_csv(self, instances, headers, name):
341342
csvwriter = csv.DictWriter(dest, delimiter=",", fieldnames=headers)
342343
csvwriter.writeheader()
343344
for instance in instances:
344-
csvwriter.writerow({k: str(v) for k, v in list(instance.items())})
345+
csvwriter.writerow({k: sanitize_csv_value(str(v)) for k, v in list(instance.items())})
345346
return {"name": f"{name}.csv", "outputfile": dest}
346347

347348
def to_shp(self, instances, headers, name):
@@ -399,3 +400,7 @@ def to_geojson(self, instances, headers, name): # a part of the code exists in
399400

400401
feature_collection = {"type": "FeatureCollection", "features": features}
401402
return feature_collection
403+
404+
def sanitize_csv_value(value):
405+
return value
406+
return re.sub(r'^([@]|[=]|[+]|[-])', '\'\g<1>', value)

0 commit comments

Comments
 (0)