From 9002eaa25921ed295367fb33f611c0cb59fc459e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 17 Apr 2016 21:54:12 +0200 Subject: [PATCH] Fix exclude filters with trailing slash --- src/restic/filter/filter.go | 2 ++ src/restic/filter/filter_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/restic/filter/filter.go b/src/restic/filter/filter.go index 4092b4025..7105a76a0 100644 --- a/src/restic/filter/filter.go +++ b/src/restic/filter/filter.go @@ -21,6 +21,8 @@ func Match(pattern, str string) (matched bool, err error) { return true, nil } + pattern = filepath.Clean(pattern) + if str == "" { return false, ErrBadString } diff --git a/src/restic/filter/filter_test.go b/src/restic/filter/filter_test.go index d44dc14e8..096edb4c6 100644 --- a/src/restic/filter/filter_test.go +++ b/src/restic/filter/filter_test.go @@ -36,6 +36,15 @@ var matchTests = []struct { {"tesT.*", "/foo/bar/test.go", false}, {"bar/*", "/foo/bar/baz", 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/test.go", true}, {"/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/**/hidden*/**/c", "/home/user/work/x/y/hidden/z/a/b/c", true}, {"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/*/bar/test.*", "c:/foo/bar/test.go", false}, }