Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

imsodin
Copy link
Member

@imsodin imsodin commented Oct 17, 2016

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.

@calmh
Copy link
Member

calmh commented Oct 20, 2016

@st-jenkins add to white list

@calmh
Copy link
Member

calmh commented Oct 20, 2016

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).

@imsodin
Copy link
Member Author

imsodin commented Oct 20, 2016

Would this test do?

@AudriusButkevicius
Copy link
Member

I wonder if the pattern separators are normalised somewhere along the way, so that this gets fixed on windows.

@imsodin
Copy link
Member Author

imsodin commented Oct 20, 2016

@AudriusButkevicius By normalised do you mean converted to slashs? If yes, this happens here.

@AudriusButkevicius
Copy link
Member

@st-review lgtm

@st-review
Copy link

@AudriusButkevicius: Noted! Need another LGTM or explicit merge command.

@calmh
Copy link
Member

calmh commented Oct 21, 2016

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

@imsodin
Copy link
Member Author

imsodin commented Oct 21, 2016

Changed it to calmh's test function and yes, it does pass.

@calmh
Copy link
Member

calmh commented Oct 21, 2016

👍

@calmh
Copy link
Member

calmh commented Oct 21, 2016

@st-jenkins retest this please

@calmh
Copy link
Member

calmh commented Oct 21, 2016

@st-review lgtm

@st-review
Copy link

@calmh: Noted! Need another LGTM or explicit merge command.

@calmh
Copy link
Member

calmh commented Oct 21, 2016

wat

@calmh
Copy link
Member

calmh commented Oct 21, 2016

@st-review merge it then

@st-review
Copy link

@calmh: Build status is pending. I'll wait until it goes green and then merge!

st-review pushed a commit that referenced this pull request Oct 21, 2016
@st-review
Copy link

👌 Merged as 7c37301. Thanks, @imsodin!

@st-review st-review closed this Oct 21, 2016
@imsodin imsodin deleted the PR-ignore branch August 25, 2017 13:36
@st-review st-review added the pr-merged Legacy label used in the past for pull requests merged to the main tree label Jan 15, 2018
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jul 15, 2018
@syncthing syncthing locked and limited conversation to collaborators Jul 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion pr-merged Legacy label used in the past for pull requests merged to the main tree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants