fix: Avoiding errors with uncommon lines

- Excluding first from data parsed all lines that
  are comments or empty
- Skipping lines with failing indexes
features_csvimport
chrisr3d 3 years ago
parent 3d7de2dc22
commit c5c5c16ff1
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
  1. 9
      misp_modules/modules/import_mod/csvimport.py

@ -125,7 +125,10 @@ class CsvParser():
score = self.__get_score()
if attribute_indexes:
for line in self.data:
base_attribute = self.__score_mapping[score](line, attribute_indexes)
try:
base_attribute = self.__score_mapping[score](line, attribute_indexes)
except IndexError:
continue
for index in types_indexes:
attribute = {'type': self.header[index], 'value': line[index]}
attribute.update(base_attribute)
@ -203,11 +206,11 @@ def __any_mandatory_misp_field(header):
def __special_parsing(data, delimiter):
return list(line.split(delimiter) for line in csv.reader(io.TextIOWrapper(io.BytesIO(data.encode()), encoding='utf-8')))
return list(line.split(delimiter) for line in csv.reader(io.TextIOWrapper(io.BytesIO(data.encode()), encoding='utf-8')) if line and not line.startswith('#'))
def __standard_parsing(data):
return list(line for line in csv.reader(io.TextIOWrapper(io.BytesIO(data.encode()), encoding='utf-8')))
return list(line for line in csv.reader(io.TextIOWrapper(io.BytesIO(data.encode()), encoding='utf-8')) if line and not line[0].startswith('#'))
def handler(q=False):

Loading…
Cancel
Save