Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Fix Bitwarden CSV import (#542)

Leendert de Borstef7398b47af5
diff --git a/src/Utilities/AliasVault.ImportExport/Converters/BooleanConverter.cs b/src/Utilities/AliasVault.ImportExport/Converters/BooleanConverter.cs
new file mode 100644
index 000000000..fcf758511
--- /dev/null
+++ b/src/Utilities/AliasVault.ImportExport/Converters/BooleanConverter.cs
@@ -0,0 +1,44 @@
+//-----------------------------------------------------------------------
+// <copyright file="BooleanConverter.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.ImportExport.Converters;
+
+using CsvHelper;
+using CsvHelper.Configuration;
+using CsvHelper.TypeConversion;
+
+/// <summary>
+/// Boolean converter for CSV import.
+/// </summary>
+public class BooleanConverter : DefaultTypeConverter
+{
+ /// <summary>
+ /// Converts a string to a boolean.
+ /// </summary>
+ /// <param name="text">The string to convert.</param>
+ /// <param name="row">The current row.</param>
+ /// <param name="memberMapData">The member map data.</param>
+ /// <returns>The converted boolean.</returns>
+ public override object ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData)
+ {
+ if (string.IsNullOrEmpty(text)) {
+ return false;
+ }
+
+ var trimmedText = text.ToLowerInvariant().Trim();
+
+ switch (trimmedText) {
+ case "1":
+ case "true":
+ case "yes":
+ case "on":
+ return true;
+ default:
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Utilities/AliasVault.ImportExport/Models/Imports/BitwardenCsvRecord.cs b/src/Utilities/AliasVault.ImportExport/Models/Imports/BitwardenCsvRecord.cs
index 519f8ef69..bc6cbb289 100644
--- a/src/Utilities/AliasVault.ImportExport/Models/Imports/BitwardenCsvRecord.cs
+++ b/src/Utilities/AliasVault.ImportExport/Models/Imports/BitwardenCsvRecord.cs
@@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
+using AliasVault.ImportExport.Converters;
using CsvHelper.Configuration.Attributes;
namespace AliasVault.ImportExport.Models.Imports;
@@ -24,7 +25,8 @@ public class BitwardenCsvRecord
/// Gets or sets whether the item is favorited.
/// </summary>
[Name("favorite")]
- public bool Favorite { get; set; }
+ [TypeConverter(typeof(BooleanConverter))]
+ public bool Favorite { get; set; } = false;
/// <summary>
/// Gets or sets the type of the item.