From 181939c8419794f14fc0248188111b6e1673e7e0 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 5 Apr 2016 06:35:51 +0000 Subject: [PATCH] lib/ignore: Correct case insensitive matching on Mac/Windows There was a bug in that we only did the lowercase folding when the pattern had an explicit (?i), which is not the case on Windows/Mac necessarily. --- lib/ignore/ignore.go | 6 +++++- lib/ignore/ignore_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index 12ddf4d2e..d52c130b5 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -229,8 +229,12 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([] } if strings.HasPrefix(line, "(?i)") { - line = strings.ToLower(line[4:]) pattern.foldCase = true + line = line[4:] + } + + if pattern.foldCase { + line = strings.ToLower(line) } var err error diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index 7d42b2dc7..6ea3d6c66 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -531,3 +531,28 @@ func TestWindowsPatterns(t *testing.T) { } } } + +func TestAutomaticCaseInsensitivity(t *testing.T) { + // We should do case insensitive matching by default on some platforms. + if runtime.GOOS != "windows" && runtime.GOOS != "darwin" { + t.Skip("Windows/Mac specific test") + return + } + + stignore := ` + A/B + c/d + ` + pats := New(true) + err := pats.Parse(bytes.NewBufferString(stignore), ".stignore") + if err != nil { + t.Fatal(err) + } + + tests := []string{`a/B`, `C/d`} + for _, pat := range tests { + if !pats.Match(pat) { + t.Errorf("Should match %s", pat) + } + } +}