From b2ec186ccb14a48b3e4370925bc05fb439081d06 Mon Sep 17 00:00:00 2001 From: chrisr3d Date: Mon, 29 Jan 2018 17:04:32 +0100 Subject: [PATCH] Updated delimiter finder method --- misp_modules/modules/import_mod/csvimport.py | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/misp_modules/modules/import_mod/csvimport.py b/misp_modules/modules/import_mod/csvimport.py index 50e9837..7e0107f 100644 --- a/misp_modules/modules/import_mod/csvimport.py +++ b/misp_modules/modules/import_mod/csvimport.py @@ -30,13 +30,11 @@ def handler(q=False): for line in f: # split comments from data if '#' in line: - l = line.split('#')[0] - if l: - data.append(l) - #else: - #header.append(line) + l = line.split('#')[0].strip() else: - data.append(line) + l = line.strip() + if l: + data.append(l) # find which delimiter is used delimiter, length = findDelimiter(config, data) # build the attributes @@ -47,9 +45,16 @@ def handler(q=False): def findDelimiter(header, data): n = len(header) if n > 1: - for d in (';', '|', '/', ',', ' '): - if data[0].count(d) == (n-1): - return d, n + tmpData = [] + for da in data: + tmp = [] + for d in (';', '|', '/', ',', '\t', ' ',): + if da.count(d) == (n-1): + tmp.append(d) + if len(tmp) == 1 and tmp == tmpData: + return tmpData[0], n + else: + tmpData = tmp else: return None, 1