From 9fed75d59c1ea5d008eddc41d519c5ddeabc5751 Mon Sep 17 00:00:00 2001 From: Lode Hoste Date: Mon, 30 Mar 2015 22:41:12 +0200 Subject: [PATCH] Support case-insensitive ignores (fixes #1511). --- internal/fnmatch/fnmatch.go | 7 +++++++ internal/fnmatch/fnmatch_test.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/internal/fnmatch/fnmatch.go b/internal/fnmatch/fnmatch.go index d64cf887b..d2a0b302a 100644 --- a/internal/fnmatch/fnmatch.go +++ b/internal/fnmatch/fnmatch.go @@ -38,6 +38,13 @@ func Convert(pattern string, flags int) (*regexp.Regexp, error) { } } + // Support case insensitive ignores + ignore := strings.TrimPrefix(pattern, "(?i)") + if ignore != pattern { + flags |= FNM_CASEFOLD + pattern = ignore + } + if flags&FNM_NOESCAPE != 0 { pattern = strings.Replace(pattern, "\\", "\\\\", -1) } else { diff --git a/internal/fnmatch/fnmatch_test.go b/internal/fnmatch/fnmatch_test.go index 251e5a9b6..cbba86347 100644 --- a/internal/fnmatch/fnmatch_test.go +++ b/internal/fnmatch/fnmatch_test.go @@ -53,6 +53,8 @@ var testcases = []testcase{ {"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, true}, {"foo.txt", "foo.TXT", FNM_CASEFOLD, true}, + {"foo.txt", "foo.TXT", 0, false}, + {"(?i)foo.txt", "foo.TXT", 0, true}, // These characters are literals in glob, but not in regexp. {"hey$hello", "hey$hello", 0, true},