From ce40a803d85f90b5078ecd4d7c374714c43940c8 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 23 Jun 2018 14:46:23 -0400 Subject: [PATCH] importers parse --- src/importers/baseImporter.ts | 4 ++-- src/importers/bitwardenCsvImporter.ts | 3 ++- src/importers/importer.ts | 2 +- src/importers/keepassxCsvImporter.ts | 3 ++- src/importers/lastpassCsvImporter.ts | 10 ++++++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/importers/baseImporter.ts b/src/importers/baseImporter.ts index c65813dadb..dccd7114e7 100644 --- a/src/importers/baseImporter.ts +++ b/src/importers/baseImporter.ts @@ -50,15 +50,15 @@ export abstract class BaseImporter { const result = papa.parse(data, { header: header, encoding: 'UTF-8', + skipEmptyLines: false, }); if (result.errors != null && result.errors.length > 0) { result.errors.forEach((e) => { // tslint:disable-next-line console.warn('Error parsing row ' + e.row + ': ' + e.message); }); - return null; } - return result.data; + return result.data && result.data.length > 0 ? result.data : null; } protected parseSingleRowCsv(rowData: string) { diff --git a/src/importers/bitwardenCsvImporter.ts b/src/importers/bitwardenCsvImporter.ts index ce3729468e..4643e17021 100644 --- a/src/importers/bitwardenCsvImporter.ts +++ b/src/importers/bitwardenCsvImporter.ts @@ -14,7 +14,7 @@ import { FieldType } from '../enums/fieldType'; import { SecureNoteType } from '../enums/secureNoteType'; export class BitwardenCsvImporter extends BaseImporter implements Importer { - import(data: string): ImportResult { + parse(data: string): ImportResult { const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { @@ -104,6 +104,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer { } }); + result.success = true; return result; } } diff --git a/src/importers/importer.ts b/src/importers/importer.ts index 453f88440d..e6df305dde 100644 --- a/src/importers/importer.ts +++ b/src/importers/importer.ts @@ -1,5 +1,5 @@ import { ImportResult } from '../models/domain/importResult'; export interface Importer { - import(data: string): ImportResult; + parse(data: string): ImportResult; } diff --git a/src/importers/keepassxCsvImporter.ts b/src/importers/keepassxCsvImporter.ts index 30eee8f115..c8ab05ec9f 100644 --- a/src/importers/keepassxCsvImporter.ts +++ b/src/importers/keepassxCsvImporter.ts @@ -10,7 +10,7 @@ import { LoginView } from '../models/view/loginView'; import { CipherType } from '../enums/cipherType'; export class KeePassXCsvImporter extends BaseImporter implements Importer { - import(data: string): ImportResult { + parse(data: string): ImportResult { const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { @@ -62,6 +62,7 @@ export class KeePassXCsvImporter extends BaseImporter implements Importer { } }); + result.success = true; return result; } } diff --git a/src/importers/lastpassCsvImporter.ts b/src/importers/lastpassCsvImporter.ts index 38809d1d49..1177686e5f 100644 --- a/src/importers/lastpassCsvImporter.ts +++ b/src/importers/lastpassCsvImporter.ts @@ -14,7 +14,7 @@ import { CipherType } from '../enums/cipherType'; import { SecureNoteType } from '../enums/secureNoteType'; export class LastPassCsvImporter extends BaseImporter implements Importer { - import(data: string): ImportResult { + parse(data: string): ImportResult { const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { @@ -22,7 +22,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { return result; } - results.forEach((value) => { + results.forEach((value, index) => { let folderIndex = result.folders.length; const cipherIndex = result.ciphers.length; const hasFolder = this.getValueOrDefault(value.grouping, '(none)') !== '(none)'; @@ -39,6 +39,11 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { } const cipher = this.buildBaseCipher(value); + if (cipher.name === '--' && results.length > 2 && index >= (results.length - 2)) { + // LastPass file traditionally has two empty lines at the end + return; + } + if (cipher.type === CipherType.Login) { cipher.notes = this.getValueOrDefault(value.extra); cipher.login = new LoginView(); @@ -75,6 +80,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { } }); + result.success = true; return result; }