From 7c2d5448e89eb0c4c79d32f4d77ee77651ebab77 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 27 Dec 2016 10:36:02 -0500 Subject: [PATCH] catch bad data on all importers --- src/app/services/importService.js | 14 ++------------ src/app/tools/toolsImportController.js | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/app/services/importService.js b/src/app/services/importService.js index 482189d7c6..813b705be1 100644 --- a/src/app/services/importService.js +++ b/src/app/services/importService.js @@ -190,8 +190,7 @@ function parseData(data) { var folders = [], sites = [], - siteRelationships = [], - badDataSites = 0; + siteRelationships = []; angular.forEach(data, function (value, key) { var folderIndex = folders.length, @@ -209,10 +208,6 @@ } } - if ((!value.name || value.name === '') && (!value.password || value.password === '')) { - badDataSites++; - } - sites.push({ favorite: value.fav === '1', uri: value.url && value.url !== '' ? trimUri(value.url) : null, @@ -237,12 +232,7 @@ } }); - if (badDataSites && badDataSites > (data.length / 2)) { - error('CSV data is not formatted correctly from LastPass. Please check your import file and try again.'); - } - else { - success(folders, sites, siteRelationships); - } + success(folders, sites, siteRelationships); } } diff --git a/src/app/tools/toolsImportController.js b/src/app/tools/toolsImportController.js index 14f67d1845..ee3731f6e1 100644 --- a/src/app/tools/toolsImportController.js +++ b/src/app/tools/toolsImportController.js @@ -13,10 +13,17 @@ function importSuccess(folders, sites, folderRelationships) { if (!folders.length && !sites.length) { - $uibModalInstance.dismiss('cancel'); - toastr.error('Nothing was imported.'); + importError('Nothing was imported.'); return; } + else if (sites.length) { + var halfway = Math.floor(sites.length / 2); + var last = sites.length - 1; + if (siteIsBadData(sites[0]) && siteIsBadData(sites[halfway]) && siteIsBadData(sites[last])) { + importError('CSV data is not formatted correctly. Please check your import file and try again.'); + return; + } + } apiService.ciphers.import({ folders: cipherService.encryptFolders(folders, cryptoService.getKey()), @@ -31,6 +38,10 @@ }, importError); } + function siteIsBadData(site) { + return (site.name === null || site.name === '--') && (site.password === null || site.password === ''); + } + function importError(error) { $analytics.eventTrack('Import Data Failed', { label: $scope.model.source }); $uibModalInstance.dismiss('cancel');