commit 47651e781b0d093678e5fcbb415d6dd00b9933c0
parent 8f09028fc5a53273584a2b7589f63ed33005a6a2
Author: Sean Enck <sean@ttypty.com>
Date: Tue, 10 Jun 2025 10:59:58 -0400
downgrade search from glob to contains instead of detecting if glob
Diffstat:
3 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/internal/app/list.go b/internal/app/list.go
@@ -88,13 +88,14 @@ func createFilter(filter string) (bool, func(string, string) (bool, error)) {
if filter == "" {
return false, nil
}
- parts := kdbx.SplitPath(filter)
- for _, p := range parts {
- if strings.ContainsAny(p, "*?[^]\\-") {
- return true, kdbx.Glob
- }
- }
return true, func(criteria, path string) (bool, error) {
+ ok, err := kdbx.Glob(criteria, path)
+ if err != nil {
+ return false, err
+ }
+ if ok {
+ return true, nil
+ }
return strings.Contains(path, criteria), nil
}
}
diff --git a/internal/kdbx/core.go b/internal/kdbx/core.go
@@ -82,7 +82,7 @@ func NewTransaction() (*Transaction, error) {
}
func splitComponents(path string) ([]string, string, error) {
- if len(SplitPath(path)) < 2 {
+ if len(splitPath(path)) < 2 {
return nil, "", errPath
}
if strings.HasPrefix(path, pathSep) {
@@ -95,7 +95,7 @@ func splitComponents(path string) ([]string, string, error) {
return nil, "", errors.New("unwilling to operate on path with empty segment")
}
title := Base(path)
- parts := SplitPath(Directory(path))
+ parts := splitPath(Directory(path))
return parts, title, nil
}
@@ -181,7 +181,7 @@ func (e Entity) Value(key string) (string, bool) {
// Base will get the base name of input path
func Base(s string) string {
- parts := SplitPath(s)
+ parts := splitPath(s)
if len(parts) == 0 {
return s
}
@@ -190,7 +190,7 @@ func Base(s string) string {
// Directory will get the directory/group for the given path
func Directory(s string) string {
- parts := SplitPath(s)
+ parts := splitPath(s)
return NewPath(parts[0 : len(parts)-1]...)
}
@@ -212,8 +212,8 @@ func IsLeafAttribute(path, attr string) bool {
return strings.HasSuffix(path, pathSep+attr)
}
-// SplitPath will split a path based on the separator
-func SplitPath(path string) []string {
+// splitPath will split a path based on the separator
+func splitPath(path string) []string {
return strings.Split(path, pathSep)
}
diff --git a/internal/kdbx/core_test.go b/internal/kdbx/core_test.go
@@ -167,14 +167,3 @@ func TestEntityValue(t *testing.T) {
t.Error("values are not set")
}
}
-
-func TestSplitPath(t *testing.T) {
- parts := kdbx.SplitPath("a")
- if len(parts) != 1 || parts[0] != "a" {
- t.Errorf("invalid split: %v", parts)
- }
- parts = kdbx.SplitPath("a/b")
- if len(parts) != 2 || parts[0] != "a" || parts[1] != "b" {
- t.Errorf("invalid split: %v", parts)
- }
-}