Skip to content

Commit

Permalink
fix for s #1 - sanitize csv values
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongundel committed Jun 14, 2022
1 parent f3a0bc5 commit 3231ef6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion arches/app/search/search_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import logging
from io import StringIO
from io import BytesIO
import re
from django.contrib.gis.geos import GeometryCollection, GEOSGeometry
from django.core.files import File
from django.utils.translation import ugettext as _
Expand Down Expand Up @@ -341,7 +342,7 @@ def to_csv(self, instances, headers, name):
csvwriter = csv.DictWriter(dest, delimiter=",", fieldnames=headers)
csvwriter.writeheader()
for instance in instances:
csvwriter.writerow({k: str(v) for k, v in list(instance.items())})
csvwriter.writerow({k: sanitize_csv_value(str(v)) for k, v in list(instance.items())})
return {"name": f"{name}.csv", "outputfile": dest}

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

feature_collection = {"type": "FeatureCollection", "features": features}
return feature_collection

def sanitize_csv_value(value):
return value
return re.sub(r'^([@]|[=]|[+]|[-])', '\'\g<1>', value)

0 comments on commit 3231ef6

Please sign in to comment.