Skip to content

Commit

Permalink
Ensure we always have a display name for custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Mar 4, 2024
1 parent f8b5408 commit 29ffc8b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
15 changes: 9 additions & 6 deletions lib/src/kee_vault_model/browser_entry_settings_v1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class BrowserEntrySettingsV1 {
final f = Field(
valuePath: 'UserName',
page: max(ff.page, 1),
uuid: guidService.newGuid(),
uuid: guidService.newGuidAsBase64(),
type: FieldType.Text,
matcherConfigs: [mc],
);
Expand All @@ -364,7 +364,7 @@ class BrowserEntrySettingsV1 {
final f = Field(
valuePath: 'Password',
page: max(ff.page, 1),
uuid: guidService.newGuid(),
uuid: guidService.newGuidAsBase64(),
type: FieldType.Password,
matcherConfigs: [mc]);
if (ff.placeholderHandling != PlaceholderHandling.Default.name) {
Expand All @@ -378,11 +378,14 @@ class BrowserEntrySettingsV1 {
id: ff.fieldId,
name: ff.name,
);
final newUniqueId = guidService.newGuidAsBase64();
final f = Field(
name: ff.displayName,
name: (ff.displayName?.isNotEmpty ?? false)
? ff.displayName
: newUniqueId,
valuePath: '.',
page: max(ff.page, 1),
uuid: guidService.newGuid(),
uuid: newUniqueId,
type: Utilities.formFieldTypeToFieldType(
ff.type ?? FormFieldType.TEXT),
matcherConfigs: [mc],
Expand All @@ -398,7 +401,7 @@ class BrowserEntrySettingsV1 {
if (!usernameFound) {
fields.add(Field(
valuePath: 'UserName',
uuid: guidService.newGuid(),
uuid: guidService.newGuidAsBase64(),
type: FieldType.Text,
matcherConfigs: [
FieldMatcherConfig(
Expand All @@ -408,7 +411,7 @@ class BrowserEntrySettingsV1 {
if (!passwordFound) {
fields.add(Field(
valuePath: 'Password',
uuid: guidService.newGuid(),
uuid: guidService.newGuidAsBase64(),
type: FieldType.Password,
matcherConfigs: [
FieldMatcherConfig(
Expand Down
4 changes: 4 additions & 0 deletions lib/src/kee_vault_model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class Field {
ffValue = '{USERNAME}';
}

if (displayName?.isEmpty ?? true) {
displayName = uuid;
}

if (ffValue != '') {
return BrowserFieldModelV1(
name: htmlName,
Expand Down
12 changes: 9 additions & 3 deletions lib/src/utils/guid_service.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import 'dart:typed_data';

import 'package:kdbx/src/utils/byte_utils.dart';
import 'package:uuid/uuid.dart';

abstract class IGuidService {
String newGuid();
//String newGuid();
String newGuidAsBase64();
}

class GuidService implements IGuidService {
@override
String newGuid() {
return const Uuid().v4();
String newGuidAsBase64() {
final buf = Uint8List(16);
const Uuid().v4buffer(buf);
return buf.encodeBase64();
}
}
Loading

0 comments on commit 29ffc8b

Please sign in to comment.