From e312fdd4f8ca8e6510114be28ff2f0fc3cc73cd5 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 8 Aug 2015 11:53:14 +0200 Subject: [PATCH] Handle multiple case insensitivity prefixes in ignores (fixes #2134) --- internal/fnmatch/fnmatch.go | 7 ++++--- internal/fnmatch/fnmatch_test.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/fnmatch/fnmatch.go b/internal/fnmatch/fnmatch.go index 0147be886..398930455 100644 --- a/internal/fnmatch/fnmatch.go +++ b/internal/fnmatch/fnmatch.go @@ -38,9 +38,10 @@ func Convert(pattern string, flags int) (*regexp.Regexp, error) { } } - // Support case insensitive ignores - ignore := strings.TrimPrefix(pattern, "(?i)") - if ignore != pattern { + // Support case insensitive ignores. We do the loop because we may in some + // circumstances end up with multiple insensitivity prefixes + // ("(?i)(?i)foo"), which should be accepted. + for ignore := strings.TrimPrefix(pattern, "(?i)"); ignore != pattern; ignore = strings.TrimPrefix(pattern, "(?i)") { flags |= CaseFold pattern = ignore } diff --git a/internal/fnmatch/fnmatch_test.go b/internal/fnmatch/fnmatch_test.go index 86372dcb2..10f989090 100644 --- a/internal/fnmatch/fnmatch_test.go +++ b/internal/fnmatch/fnmatch_test.go @@ -54,6 +54,7 @@ var testcases = []testcase{ {"foo.txt", "foo.TXT", CaseFold, true}, {"(?i)foo.txt", "foo.TXT", 0, true}, + {"(?i)(?i)foo.txt", "foo.TXT", 0, true}, // repeated prefix should be fine {"(?i)**foo.txt", "/dev/tmp/foo.TXT", 0, true}, {"(?i)!**foo.txt", "/dev/tmp/foo.TXT", 0, false},