2
2
mirror of https://github.com/octoleo/restic.git synced 2025-01-10 18:04:38 +00:00

Fix exclude filters with trailing slash

This commit is contained in:
Alexander Neumann 2016-04-17 21:54:12 +02:00
parent 75dd9e0fee
commit 9002eaa259
2 changed files with 13 additions and 0 deletions

View File

@ -21,6 +21,8 @@ func Match(pattern, str string) (matched bool, err error) {
return true, nil return true, nil
} }
pattern = filepath.Clean(pattern)
if str == "" { if str == "" {
return false, ErrBadString return false, ErrBadString
} }

View File

@ -36,6 +36,15 @@ var matchTests = []struct {
{"tesT.*", "/foo/bar/test.go", false}, {"tesT.*", "/foo/bar/test.go", false},
{"bar/*", "/foo/bar/baz", true}, {"bar/*", "/foo/bar/baz", true},
{"bar", "/foo/bar", true}, {"bar", "/foo/bar", true},
{"/foo/bar", "/foo/bar", true},
{"/foo/bar/", "/foo/bar", true},
{"/foo/bar", "/foo/baz", false},
{"/foo/bar", "/foo/baz/", false},
{"/foo///bar", "/foo/bar", true},
{"/foo/../bar", "/foo/bar", false},
{"/foo/../bar", "/bar", true},
{"/foo", "/foo/baz", true},
{"/foo/", "/foo/baz", true},
{"bar", "/foo/bar/baz", true}, {"bar", "/foo/bar/baz", true},
{"bar", "/foo/bar/test.go", true}, {"bar", "/foo/bar/test.go", true},
{"/foo/*test.*", "/foo/bar/test.go", false}, {"/foo/*test.*", "/foo/bar/test.go", false},
@ -74,6 +83,8 @@ var matchTests = []struct {
{"user/**/important*", "/home/user/work/x/y/hidden/x", false}, {"user/**/important*", "/home/user/work/x/y/hidden/x", false},
{"user/**/hidden*/**/c", "/home/user/work/x/y/hidden/z/a/b/c", true}, {"user/**/hidden*/**/c", "/home/user/work/x/y/hidden/z/a/b/c", true},
{"c:/foo/*test.*", "c:/foo/bar/test.go", false}, {"c:/foo/*test.*", "c:/foo/bar/test.go", false},
{"c:/foo", "c:/foo/bar", true},
{"c:/foo/", "c:/foo/bar", true},
{"c:/foo/*/test.*", "c:/foo/bar/test.go", true}, {"c:/foo/*/test.*", "c:/foo/bar/test.go", true},
{"c:/foo/*/bar/test.*", "c:/foo/bar/test.go", false}, {"c:/foo/*/bar/test.*", "c:/foo/bar/test.go", false},
} }