Skip to content

Commit

Permalink
Whitelist PXL_*._exported_* from default banned file exclusion ._*.*`
Browse files Browse the repository at this point in the history
Fixes #632
  • Loading branch information
simulot committed Jan 19, 2025
1 parent 72b1b1e commit 7a09bcb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit 7a09bcb

Please sign in to comment.