From 7a09bcb982250e8601fe7035926468c6172e1fd2 Mon Sep 17 00:00:00 2001 From: simulot Date: Sun, 19 Jan 2025 19:48:58 +0100 Subject: [PATCH] Whitelist PXL_*._exported_* from default banned file exclusion ._*.*` Fixes #632 --- internal/namematcher/list.go | 12 ++++++++++-- internal/namematcher/list_test.go | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/namematcher/list.go b/internal/namematcher/list.go index d661e151..312ac177 100644 --- a/internal/namematcher/list.go +++ b/internal/namematcher/list.go @@ -59,14 +59,21 @@ func patternToRe(pattern string) (*regexp.Regexp, error) { buf := []byte(pattern) r.WriteString("(?i)") // make the pattern case insensitive + isFirtRune := true for len(buf) > 0 { buf, b = fetchRune(buf) switch b { + case '/': + if isFirtRune { + r.WriteString(`(^|/)`) + } else { + r.WriteRune('/') + } case '*': - r.WriteString(`[^./]*`) + r.WriteString(`[^/]*`) case '?': - r.WriteString(`[^./]`) + r.WriteString(`[^/]`) case '.', '^', '$', '(', ')', '|': r.WriteRune('\\') r.WriteRune(b) @@ -96,6 +103,7 @@ func patternToRe(pattern string) (*regexp.Regexp, error) { default: r.WriteRune(b) } + isFirtRune = false } if inBrackets { return nil, fmt.Errorf("invalid file name pattern: %s", pattern) diff --git a/internal/namematcher/list_test.go b/internal/namematcher/list_test.go index 9d01d7d7..47d5c3c1 100644 --- a/internal/namematcher/list_test.go +++ b/internal/namematcher/list_test.go @@ -1,6 +1,8 @@ package namematcher -import "testing" +import ( + "testing" +) func TestList_Match(t *testing.T) { type args struct { @@ -112,14 +114,17 @@ func TestList_Match(t *testing.T) { {"@eaDir/SYNOFILE_THUMB_M_000213.jpg", true}, }, }, + { - name: "._*", + name: "/._*", want: []args{ {"hello.world", false}, {"._hello.world", true}, {"/path/to/file.exe", false}, {"/path/to/._file.exe", true}, {"/path/to/file", false}, + {"/path/to/PXL_20210825_041449609._exported_699_1629864935.jpg", false}, + {"PXL_20210825_041449609._exported_699_1629864935.jpg", false}, }, }, }