mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-15 10:55:31 -04:00
Fix Bitwarden CSV import (#542)
This commit is contained in:
committed by
Leendert de Borst
parent
dc769bb5d4
commit
ef7398b47a
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user