Ignore patterns should be case insensitive on OS X and Windows

This commit is contained in:
Jakob Borg
2014-09-16 23:14:03 +02:00
parent 592b13d7db
commit 384c543ab9
3 changed files with 45 additions and 6 deletions

View File

@@ -20,15 +20,22 @@ const (
func Convert(pattern string, flags int) (*regexp.Regexp, error) {
any := "."
if runtime.GOOS == "windows" {
flags |= FNM_NOESCAPE
switch runtime.GOOS {
case "windows":
flags |= FNM_NOESCAPE | FNM_CASEFOLD
pattern = filepath.FromSlash(pattern)
if flags&FNM_PATHNAME != 0 {
any = "[^\\\\]"
}
} else if flags&FNM_PATHNAME != 0 {
any = "[^/]"
case "darwin":
flags |= FNM_CASEFOLD
fallthrough
default:
if flags&FNM_PATHNAME != 0 {
any = "[^/]"
}
}
if flags&FNM_NOESCAPE != 0 {
pattern = strings.Replace(pattern, "\\", "\\\\", -1)
} else {

View File

@@ -50,12 +50,17 @@ var testcases = []testcase{
{"**/foo.txt", "bar/baz/foo.txt", 0, true},
{"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, true},
{"foo.txt", "foo.TXT", 0, false},
{"foo.txt", "foo.TXT", FNM_CASEFOLD, true},
}
func TestMatch(t *testing.T) {
if runtime.GOOS != "windows" {
switch runtime.GOOS {
case "windows":
testcases = append(testcases, testcase{"foo.txt", "foo.TXT", 0, true})
case "darwin":
testcases = append(testcases, testcase{"foo.txt", "foo.TXT", 0, true})
fallthrough
default:
testcases = append(testcases, testcase{"f\\[ab\\]o.txt", "f[ab]o.txt", 0, true})
testcases = append(testcases, testcase{"foo\\.txt", "foo.txt", 0, true})
testcases = append(testcases, testcase{"foo\\*.txt", "foo*.txt", 0, true})