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 (c) lanedirt. All rights reserved. +// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. +// +//----------------------------------------------------------------------- + +namespace AliasVault.ImportExport.Converters; + +using CsvHelper; +using CsvHelper.Configuration; +using CsvHelper.TypeConversion; + +/// +/// Boolean converter for CSV import. +/// +public class BooleanConverter : DefaultTypeConverter +{ + /// + /// Converts a string to a boolean. + /// + /// The string to convert. + /// The current row. + /// The member map data. + /// The converted boolean. + 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 @@ // //----------------------------------------------------------------------- +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. /// [Name("favorite")] - public bool Favorite { get; set; } + [TypeConverter(typeof(BooleanConverter))] + public bool Favorite { get; set; } = false; /// /// Gets or sets the type of the item.