From 4fc798e621017f103b7172b54d8f4a07e890445f Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Mon, 7 Sep 2020 23:43:12 +0200 Subject: [PATCH] use url as entry label if title is not defined. --- lib/src/internal/extension_utils.dart | 11 +++++++++++ lib/src/kdbx_entry.dart | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/src/internal/extension_utils.dart b/lib/src/internal/extension_utils.dart index 0558dac..9bc20e9 100644 --- a/lib/src/internal/extension_utils.dart +++ b/lib/src/internal/extension_utils.dart @@ -34,6 +34,17 @@ extension ObjectExt on T { R let(R Function(T that) op) => op(this); } +extension StringExt on String { + String takeUnlessBlank() => nullIfBlank(); + + String nullIfBlank() { + if (this == null || isEmpty) { + return null; + } + return this; + } +} + extension IterableExt on Iterable { T get singleOrNull => singleWhere((element) => true, orElse: () => null); } diff --git a/lib/src/kdbx_entry.dart b/lib/src/kdbx_entry.dart index 4ba0d42..93db068 100644 --- a/lib/src/kdbx_entry.dart +++ b/lib/src/kdbx_entry.dart @@ -325,7 +325,8 @@ class KdbxEntry extends KdbxObject { } String get label => - _plainValue(KdbxKeyCommon.TITLE) ?? _plainValue(KdbxKeyCommon.URL); + _plainValue(KdbxKeyCommon.TITLE)?.takeUnlessBlank() ?? + _plainValue(KdbxKeyCommon.URL)?.takeUnlessBlank(); set label(String label) => setString(KdbxKeyCommon.TITLE, PlainValue(label));