mirror of https://gitlab.com/bashrc2/epicyon
Extra validation on csv import
parent
4103249917
commit
beb2c5c9c7
14
content.py
14
content.py
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue