Fix Bitwarden CSV import (#542)

This commit is contained in:
Leendert de Borst
2025-03-24 17:31:26 +01:00
committed by Leendert de Borst
parent dc769bb5d4
commit ef7398b47a
2 changed files with 47 additions and 1 deletions

View File

@@ -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;
}
}
}

View File

@@ -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.