Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelist PXL_*._exported_* from default banned file exclusion ._*.*` #642

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/namematcher/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions internal/namematcher/list_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package namematcher

import "testing"
import (
"testing"
)

func TestList_Match(t *testing.T) {
type args struct {
Expand Down Expand Up @@ -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},
},
},
}
Expand Down