-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/ignore: Add directory separator to glob.Compile call #3674
Conversation
@st-jenkins add to white list |
LGTM but could we get a unit test for this as well to catch regressions in the future? Somewhere in lib/ignore/ignore_test.go should be appropriate. Also to ensure that this does the right thing on Windows as well (it should, but testing will verify it). |
Would this test do? |
I wonder if the pattern separators are normalised somewhere along the way, so that this gets fixed on windows. |
@AudriusButkevicius By normalised do you mean converted to slashs? If yes, this happens here. |
@st-review lgtm |
@AudriusButkevicius: Noted! Need another LGTM or explicit merge command. |
How about this: func TestIssue3674(t *testing.T) {
stignore := `
a*b
a**c
`
testcases := []struct {
file string
matches bool
}{
{"ab", true},
{"asdfb", true},
{"ac", true},
{"asdfc", true},
{"as/db", false},
{"as/dc", true},
}
pats := New(true)
err := pats.Parse(bytes.NewBufferString(stignore), ".stignore")
if err != nil {
t.Fatal(err)
}
for _, tc := range testcases {
res := pats.Match(tc.file).IsIgnored()
if res != tc.matches {
t.Errorf("Matches(%q) == %v, expected %v", tc.file, res, tc.matches)
}
}
} Which fails now, and should hopefully pass with your patch: jb@unu:~/s/g/s/s/l/ignore $ go test -v -run TestIssue3674
=== RUN TestIssue3674
--- FAIL: TestIssue3674 (0.00s)
ignore_test.go:768: Matches("as/db") == true, expected false
FAIL
FAIL github.com/syncthing/syncthing/lib/ignore 0.006s |
Changed it to calmh's test function and yes, it does pass. |
👍 |
@st-jenkins retest this please |
@st-review lgtm |
@calmh: Noted! Need another LGTM or explicit merge command. |
wat |
@st-review merge it then |
@calmh: Build status is |
GitHub-Pull-Request: #3674 LGTM: calmh
The current implementation of gobwas/glob in lib/ignore does not account for directory separators ('/'). Thus the distinction between '' and '**' is meaningless. Currently both the patterns 'ab' and 'a**b' match the path 'a/b'.
I confirmed the current behavior looking at the last file received entry in the GUI. But as I am only familiar with syncthing-inotify and it uses lib/ignore for its filtering as well, I tested this PR with debug information from syncthing-inotify. The test setup is trivial, just put something like the strings mentioned into .stignore.