mirror of https://github.com/MISP/misp-modules
fix: Avoiding errors with uncommon lines
- Excluding first from data parsed all lines that are comments or empty - Skipping lines with failing indexespull/338/head
parent
3d7de2dc22
commit
c5c5c16ff1
|
@ -125,7 +125,10 @@ class CsvParser():
|
|||
score = self.__get_score()
|
||||
if attribute_indexes:
|
||||
for line in self.data:
|
||||
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…
Reference in New Issue