diff --git a/filter/filter.go b/filter/filter.go
index 18f7aa718..6f9f55cc7 100644
--- a/filter/filter.go
+++ b/filter/filter.go
@@ -45,7 +45,8 @@ func match(patterns, strs []string) (matched bool, err error) {
 	if ok, pos := hasDoubleWildcard(patterns); ok {
 		// gradually expand '**' into separate wildcards
 		for i := 0; i <= len(strs)-len(patterns)+1; i++ {
-			newPat := patterns[:pos]
+			newPat := make([]string, pos)
+			copy(newPat, patterns[:pos])
 			for k := 0; k < i; k++ {
 				newPat = append(newPat, "*")
 			}
diff --git a/filter/filter_test.go b/filter/filter_test.go
index fb4ab94b7..112fd931d 100644
--- a/filter/filter_test.go
+++ b/filter/filter_test.go
@@ -69,6 +69,8 @@ var matchTests = []struct {
 	{"foo/**/bar/*.go", "bar/main.go", false},
 	{"foo/**/bar", "/home/user/foo/x/y/bar", true},
 	{"foo/**/bar", "/home/user/foo/x/y/bar/main.go", true},
+	{"user/**/important*", "/home/user/work/x/y/hidden/x", false},
+	{"user/**/hidden*/**/c", "/home/user/work/x/y/hidden/z/a/b/c", true},
 }
 
 func TestMatch(t *testing.T) {
@@ -268,7 +270,7 @@ var filterTests = []struct {
 		[]string{"accounting.*", "*Partner*"},
 		[]string{"*.docx", "*.xlsx"},
 		[]test{
-			// {"/home/user/foo/test.c", true},
+			{"/home/user/foo/test.c", true},
 			{"/home/user/Partner/test.docx", true},
 			{"/home/user/bar/test.docx", false},
 			{"/home/user/test.xlsx", false},
@@ -279,6 +281,24 @@ var filterTests = []struct {
 			{"/users/A/Calculation Partner.xlsx", true},
 		},
 	},
+	{
+		[]string{"accounting.*", "*Partner*", "user/**/important*"},
+		[]string{"*.docx", "*.xlsx", "user/**/*hidden*"},
+		[]test{
+			{"/home/user/foo/test.c", true},
+			{"/home/user/Partner/test.docx", true},
+			{"/home/user/bar/test.docx", false},
+			{"/home/user/test.xlsx", false},
+			{"/home/foo/test.doc", true},
+			{"/x", true},
+			{"main.go", true},
+			{"/users/A/accounting.xlsx", true},
+			{"/users/A/Calculation Partner.xlsx", true},
+			{"/home/user/work/shared/test/important Calculations/help.txt", true},
+			{"/home/user/work/shared/test/important.xlsx", true},
+			{"/home/user/work/x/y/hidden/x", false},
+		},
+	},
 }
 
 func TestFilter(t *testing.T) {