Skip to content

Commit

Permalink
fix invalid file matching regular expressions (#5083)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored and SandyXSD committed Aug 27, 2024
1 parent 4ebfe69 commit 9ba9e84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/chunk/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ func (cache *cacheStore) scanCached() {
cache.Unlock()
}

var pathReg, _ = regexp.Compile(`^chunks/\d+/\d+/\d+_\d+_\d+$`)
var pathReg, _ = regexp.Compile(`^chunks/((\d+)|([0-9a-fA-F]{2}))/\d+/\d+_\d+_\d+$`)

func (cache *cacheStore) scanStaging() {
if cache.uploader == nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/chunk/disk_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ func TestCheckPath(t *testing.T) {
{path: "chunks/111_/2222/3333_3333_3333", expected: false},
{path: "chunks/111/22_22/3333_3333_3333", expected: false},
{path: "chunks/111/22_22/3333_3333_3333", expected: false},
{path: "chunks/dd/222/3333_3333_0", expected: true}, // hash prefix
{path: "chunks/FF/222/3333_3333_0", expected: true}, // hash prefix
{path: "chunks/5D/222/3333_3333_0", expected: true}, // hash prefix
{path: "chunks/D1/222/3333_3333_0", expected: true}, // hash prefix
{path: "chunks/5DD/222/3333_3333_0", expected: false},
{path: "chunks/111D/222/3333_3333_0", expected: false},
}
for _, c := range cases {
if res := pathReg.MatchString(c.path); res != c.expected {
Expand Down

0 comments on commit 9ba9e84

Please sign in to comment.