Extra validation on csv import

merge-requests/30/head
Bob Mottram 2022-07-21 11:16:14 +01:00
parent 4103249917
commit beb2c5c9c7
1 changed files with 12 additions and 2 deletions

View File

@ -1359,6 +1359,16 @@ def extract_media_in_form_post(post_bytes, boundary, name: str):
return media_bytes, post_bytes[:image_start_location] + remainder
def _valid_follows_csv(content: str) -> bool:
"""is the given content a valid csv file containing imported follows?
"""
if ',' not in content:
return False
if 'Account address,' not in content:
return False
return True
def save_media_in_form_post(media_bytes, debug: bool,
filename_base: str = None) -> (str, str):
"""Saves the given media bytes extracted from http form POST
@ -1396,7 +1406,7 @@ def save_media_in_form_post(media_bytes, debug: bool,
filename = None
# directly search the binary array for the beginning
# of an image
# of an image, zip or csv
extension_list = {
'png': 'image/png',
'jpeg': 'image/jpeg',
@ -1472,7 +1482,7 @@ def save_media_in_form_post(media_bytes, debug: bool,
elif detected_extension == 'csv':
csv_str = media_bytes[start_pos:]
csv_str = svg_str.decode()
if ',' not in csv_str:
if not _valid_follows_csv(csv_str):
return None, None
try: