Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make CSV import more robust by handling special char decoding (#1146)
Leendert de Borstad3c0323b9ac
diff --git a/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj b/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csprojindex 4de5f17a4..3eef8a09b 100644--- a/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj+++ b/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj@@ -67,6 +67,8 @@<EmbeddedResource Include="TestData\Exports\firefox.csv" /><EmbeddedResource Include="TestData\Exports\strongbox.csv" /><EmbeddedResource Include="TestData\Exports\keepass.csv" />+ <EmbeddedResource Include="TestData\Exports\keepass_special_chars.csv" />+ <EmbeddedResource Include="TestData\Exports\keepass_escaped_quotes.csv" /><EmbeddedResource Include="TestData\Exports\keepassxc.csv" /><EmbeddedResource Include="TestData\Exports\1password_8.csv" /><EmbeddedResource Include="TestData\Exports\protonpass.csv" />diff --git a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/keepass_escaped_quotes.csv b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/keepass_escaped_quotes.csvnew file mode 100644index 000000000..7bcd94bfe--- /dev/null+++ b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/keepass_escaped_quotes.csv@@ -0,0 +1,3 @@+"Account","Login Name","Password","Web Site","Comments"+"Sample Entry","User Name","Password","https://keepass.info/","Notes"+"Entry with backslash quotes","testuser","mypass123","https://example.com","This note has \"escaped quotes\" and other stuff"\ No newline at end of filediff --git a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/keepass_special_chars.csv b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/keepass_special_chars.csvnew file mode 100644index 000000000..27189c317--- /dev/null+++ b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/keepass_special_chars.csv@@ -0,0 +1,4 @@+"Account","Login Name","Password","Web Site","Comments"+"Sample Entry","User Name","Password","https://keepass.info/","Notes"+"Sample Entry #2","Michael321","12345","https://keepass.info/help/kb/testform.html",""+"Entry with notes special chars","","DVfIsb4TGkL7oKCwyiet","","Note \"with double quotes\"'as'd as/d/asd/ z's'sd a8e89A)_@()@'\":ÄS\"d';asd;á'sd"\ No newline at end of filediff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.csindex 2493e7c6a..dd72b0ee6 100644--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs@@ -319,6 +319,82 @@ public class ImportExportTests});}+ /// <summary>+ /// Test case for importing credentials from KeePass CSV with special characters and double quotes.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task ImportCredentialsFromKeePassCsvWithSpecialChars()+ {+ // Arrange+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.keepass_special_chars.csv");++ // Act+ var importedCredentials = await KeePassImporter.ImportFromCsvAsync(fileContent);++ // Assert+ Assert.That(importedCredentials, Has.Count.EqualTo(3));++ // Test the entry with special characters and double quotes+ var specialEntry = importedCredentials.First(c => c.ServiceName == "Entry with notes special chars");+ Assert.Multiple(() =>+ {+ Assert.That(specialEntry.ServiceName, Is.EqualTo("Entry with notes special chars"));+ Assert.That(specialEntry.ServiceUrl, Is.Empty);+ Assert.That(specialEntry.Username, Is.Empty);+ Assert.That(specialEntry.Password, Is.EqualTo("DVfIsb4TGkL7oKCwyiet"));+ Assert.That(specialEntry.Notes, Does.Contain("\"Note with double quotes\""));+ Assert.That(specialEntry.Notes, Does.Contain("as'd as/d/asd/ z"));+ Assert.That(specialEntry.Notes, Does.Contain("asd;á'sd"));+ });++ // Test other entries still work correctly+ var sampleEntry = importedCredentials.First(c => c.ServiceName == "Sample Entry");+ Assert.Multiple(() =>+ {+ Assert.That(sampleEntry.ServiceName, Is.EqualTo("Sample Entry"));+ Assert.That(sampleEntry.ServiceUrl, Is.EqualTo("https://keepass.info/"));+ Assert.That(sampleEntry.Username, Is.EqualTo("User Name"));+ Assert.That(sampleEntry.Password, Is.EqualTo("Password"));+ Assert.That(sampleEntry.Notes, Is.EqualTo("Notes"));+ });+ }++ /// <summary>+ /// Test case for importing credentials from KeePass CSV with backslash-escaped quotes.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task ImportCredentialsFromKeePassCsvWithEscapedQuotes()+ {+ // Arrange+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.keepass_escaped_quotes.csv");++ // Act+ var importedCredentials = await KeePassImporter.ImportFromCsvAsync(fileContent);++ // Assert+ Assert.That(importedCredentials, Has.Count.EqualTo(2));++ // Test the entry with escaped quotes+ var escapedQuotesEntry = importedCredentials.First(c => c.ServiceName == "Entry with backslash quotes");+ Assert.Multiple(() =>+ {+ Assert.That(escapedQuotesEntry.ServiceName, Is.EqualTo("Entry with backslash quotes"));+ Assert.That(escapedQuotesEntry.ServiceUrl, Is.EqualTo("https://example.com"));+ Assert.That(escapedQuotesEntry.Username, Is.EqualTo("testuser"));+ Assert.That(escapedQuotesEntry.Password, Is.EqualTo("mypass123"));++ // The CSV decoding should have converted \" to " properly+ Assert.That(escapedQuotesEntry.Notes, Does.Contain("This note has"));+ Assert.That(escapedQuotesEntry.Notes, Does.Contain("\"escaped quotes\""));+ Assert.That(escapedQuotesEntry.Notes, Does.Contain("and other stuff"));++ // Verify that the backslashes before quotes have been properly decoded+ Assert.That(escapedQuotesEntry.Notes, Does.Not.Contain("\\\""));+ });+ }+/// <summary>/// Test case for importing credentials from KeePassXC CSV and ensuring all values are present./// </summary>diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.csindex 0c7577ba8..e79a4522e 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs@@ -10,12 +10,141 @@ namespace AliasVault.ImportExport.Importers;using AliasClientDb;using AliasVault.ImportExport.Models;using AliasVault.TotpGenerator;+using CsvHelper;+using CsvHelper.Configuration;+using System.Globalization;+using System.Text.RegularExpressions;/// <summary>/// Generic import logic./// </summary>public static class BaseImporter{+ /// <summary>+ /// Creates a CSV configuration that handles bad data and quote escaping.+ /// </summary>+ /// <returns>A CsvConfiguration with improved error handling.</returns>+ public static CsvConfiguration CreateCsvConfiguration()+ {+ return new CsvConfiguration(CultureInfo.InvariantCulture)+ {+ BadDataFound = context =>+ {+ // Log bad data but don't throw, allowing the parser to continue+ // This helps with malformed CSV entries+ return;+ },+ MissingFieldFound = null, // Ignore missing fields+ HeaderValidated = null, // Don't validate header names+ PrepareHeaderForMatch = args => args.Header?.ToLower().Trim().Replace(" ", string.Empty) ?? string.Empty,+ };+ }++ /// <summary>+ /// Creates a CsvReader with configuration and improved error handling.+ /// </summary>+ /// <param name="fileContent">The CSV file content.</param>+ /// <returns>A configured CsvReader.</returns>+ public static CsvReader CreateCsvReader(string fileContent)+ {+ var reader = new StringReader(fileContent);+ return new CsvReader(reader, CreateCsvConfiguration());+ }++ /// <summary>+ /// Imports CSV data with error handling and line number reporting.+ /// </summary>+ /// <typeparam name="T">The CSV record type.</typeparam>+ /// <param name="fileContent">The CSV file content.</param>+ /// <returns>A list of parsed CSV records.</returns>+ public static async Task<List<T>> ImportCsvDataAsync<T>(string fileContent)+ {+ using var reader = new StringReader(fileContent);+ using var csv = new CsvReader(reader, CreateCsvConfiguration());++ var records = new List<T>();+ var lineNumber = 1; // Start at 1 for header++ try+ {+ await foreach (var record in csv.GetRecordsAsync<T>())+ {+ lineNumber++;++ // Process CSV field decoding for escaped quotes and other special characters+ DecodeFields(record);++ records.Add(record);+ }+ }+ catch (Exception ex) when (!(ex is InvalidOperationException && ex.Message.Contains("line")))+ {+ // If we get any other CSV parsing error, wrap it with line information+ throw new InvalidOperationException($"Error parsing CSV data on line {lineNumber}. {ex.Message}", ex);+ }++ if (records.Count == 0)+ {+ throw new InvalidOperationException("No records found in the CSV file.");+ }++ return records;+ }++ /// <summary>+ /// Decodes CSV escaped characters in string fields of the record.+ /// Specifically handles CSV-encoded double quotes and other escape sequences.+ /// </summary>+ /// <param name="record">The CSV record to process.</param>+ private static void DecodeFields<T>(T record)+ {+ if (record == null) return;++ var type = typeof(T);+ var properties = type.GetProperties();++ foreach (var property in properties)+ {+ if (property.PropertyType == typeof(string))+ {+ var value = property.GetValue(record) as string;+ if (!string.IsNullOrEmpty(value))+ {+ var decodedValue = DecodeCsvField(value);+ property.SetValue(record, decodedValue);+ }+ }+ }+ }++ /// <summary>+ /// Decodes a CSV field value by handling escaped quotes and other CSV encoding.+ /// </summary>+ /// <param name="value">The CSV field value.</param>+ /// <returns>The decoded value.</returns>+ public static string DecodeCsvField(string value)+ {+ if (string.IsNullOrEmpty(value))+ return value;++ // Handle CSV-escaped double quotes: "" becomes "+ // But be careful not to affect other legitimate escape sequences+ var decoded = value;++ // Replace CSV-style escaped quotes (two consecutive quotes) with single quotes+ decoded = decoded.Replace("\"\"", "\"");++ // Handle common backslash escape sequences that might come from KeePass or other sources+ // Only handle specific known escape sequences to avoid breaking valid backslashes+ decoded = decoded.Replace("\\\"", "\""); // Escaped quote+ decoded = decoded.Replace("\\n", "\n"); // Escaped newline+ decoded = decoded.Replace("\\r", "\r"); // Escaped carriage return+ decoded = decoded.Replace("\\t", "\t"); // Escaped tab++ // Don't replace all backslashes as they might be legitimate (e.g., in file paths)++ return decoded;+ }/// <summary>/// Converts a list of imported credentials to a list of AliasVault credentials./// </summary>diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.csindex 843a1f262..257972098 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs@@ -25,11 +25,10 @@ public static class BitwardenImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<BitwardenCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<BitwardenCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -44,11 +43,6 @@ public static class BitwardenImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of filediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/ChromeImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/ChromeImporter.csindex c28f5aceb..0282175d1 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/ChromeImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/ChromeImporter.cs@@ -25,11 +25,10 @@ public static class ChromeImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<ChromeCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<ChromeCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -43,11 +42,6 @@ public static class ChromeImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of filediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.csindex f1e7e67b0..b2620cd3a 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from Dashlane.@@ -25,11 +22,10 @@ public static class DashlaneImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<DashlaneCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<DashlaneCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -44,11 +40,6 @@ public static class DashlaneImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/DropboxImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/DropboxImporter.csindex 844e5c72f..18a0da6e0 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/DropboxImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/DropboxImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from Dropbox Passwords.@@ -25,11 +22,10 @@ public static class DropboxImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<DropboxCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<DropboxCsvRecord>())+ foreach (var record in records){// Skip empty records (records with no title)if (string.IsNullOrWhiteSpace(record.Name))@@ -49,11 +45,6 @@ public static class DropboxImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/FirefoxImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/FirefoxImporter.csindex c697727f8..a865e750d 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/FirefoxImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/FirefoxImporter.cs@@ -25,11 +25,10 @@ public static class FirefoxImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<FirefoxCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<FirefoxCsvRecord>())+ foreach (var record in records){// Extract service name from URL, e.g. https://example.com/path -> example.com.var uri = new Uri(record.Url);@@ -46,11 +45,6 @@ public static class FirefoxImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of filediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.csindex d96b773a8..deb49a01b 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;using System.Text;/// <summary>@@ -55,11 +52,10 @@ public static class GenericCsvImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<GenericCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<GenericCsvRecord>())+ foreach (var record in records){// Skip records with no service nameif (string.IsNullOrWhiteSpace(record.ServiceName))diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassImporter.csindex f61fe3ca3..57e04fb0a 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassImporter.cs@@ -25,15 +25,14 @@ public static class KeePassImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<KeePassCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<KeePassCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{- ServiceName = record.Account,+ ServiceName = record.Account ?? string.Empty,ServiceUrl = record.Website,Username = record.LoginName,Password = record.Password,@@ -43,11 +42,6 @@ public static class KeePassImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of filediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.csindex 0d2f131db..2cda3a00b 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from KeePassXC.@@ -25,11 +22,10 @@ public static class KeePassXcImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<KeepassXcCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<KeepassXcCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -44,11 +40,6 @@ public static class KeePassXcImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of filediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.csindex bfea58e72..5fd6a2e26 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from LastPass.@@ -25,11 +22,10 @@ public static class LastPassImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<LastPassCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<LastPassCsvRecord>())+ foreach (var record in records){// Skip empty records (records with no name/title)if (string.IsNullOrWhiteSpace(record.Title))@@ -50,11 +46,6 @@ public static class LastPassImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.csindex b25c725ce..a99044dc3 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from 1Password.@@ -25,11 +22,10 @@ public static class OnePasswordImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<OnePasswordCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<OnePasswordCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -44,11 +40,6 @@ public static class OnePasswordImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of filediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.csindex 473621ad9..f06e1390a 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from ProtonPass.@@ -25,11 +22,10 @@ public static class ProtonPassImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<ProtonPassCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<ProtonPassCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -45,11 +41,6 @@ public static class ProtonPassImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/StrongboxImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/StrongboxImporter.csindex 8bff16fc6..4fb5ca5c7 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/StrongboxImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/StrongboxImporter.cs@@ -9,9 +9,6 @@ namespace AliasVault.ImportExport.Importers;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;-using CsvHelper;-using CsvHelper.Configuration;-using System.Globalization;/// <summary>/// Imports credentials from Strongbox.@@ -25,11 +22,10 @@ public static class StrongboxImporter/// <returns>The imported list of ImportedCredential objects.</returns>public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent){- using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var records = await BaseImporter.ImportCsvDataAsync<StrongboxCsvRecord>(fileContent);var credentials = new List<ImportedCredential>();- await foreach (var record in csv.GetRecordsAsync<StrongboxCsvRecord>())+ foreach (var record in records){var credential = new ImportedCredential{@@ -44,11 +40,6 @@ public static class StrongboxImportercredentials.Add(credential);}- if (credentials.Count == 0)- {- throw new InvalidOperationException("No records found in the CSV file.");- }-return credentials;}}\ No newline at end of file