From 8ce52972cdc919d5bf9ba06ca53bfd397488468f Mon Sep 17 00:00:00 2001 From: Shivam <127921762+Itachi7011@users.noreply.github.com> Date: Thu, 13 Aug 2026 16:13:47 +0530 Subject: [PATCH] fix: make FileFilter patterns case-insensitive (#859) * fix: make file filter patterns case-insensitive * test: strengthen case-insensitive file filter coverage --- internal/config/rules/system_rules.go | 6 ++++-- internal/config/rules/system_rules_test.go | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/config/rules/system_rules.go b/internal/config/rules/system_rules.go index bafa23e..4586acf 100644 --- a/internal/config/rules/system_rules.go +++ b/internal/config/rules/system_rules.go @@ -219,12 +219,13 @@ func (f *FileFilter) HasInclude() bool { } // IsUserExcluded reports whether the given path matches any user exclude pattern. +// The check is case-insensitive: both path and pattern are lowercased. func (f *FileFilter) IsUserExcluded(path string) bool { lowerPath := strings.ToLower(path) for _, pattern := range f.Exclude { expanded := expandBraces(pattern) for _, p := range expanded { - if matched, _ := doublestar.Match(p, lowerPath); matched { + if matched, _ := doublestar.Match(strings.ToLower(p), lowerPath); matched { return true } } @@ -233,6 +234,7 @@ func (f *FileFilter) IsUserExcluded(path string) bool { } // IsUserIncluded reports whether the given path matches any user include pattern. +// The check is case-insensitive: both path and pattern are lowercased. // Returns false when Include is empty (no user include restriction defined). func (f *FileFilter) IsUserIncluded(path string) bool { if !f.HasInclude() { @@ -242,7 +244,7 @@ func (f *FileFilter) IsUserIncluded(path string) bool { for _, pattern := range f.Include { expanded := expandBraces(pattern) for _, p := range expanded { - if matched, _ := doublestar.Match(p, lowerPath); matched { + if matched, _ := doublestar.Match(strings.ToLower(p), lowerPath); matched { return true } } diff --git a/internal/config/rules/system_rules_test.go b/internal/config/rules/system_rules_test.go index 2290102..34e9560 100644 --- a/internal/config/rules/system_rules_test.go +++ b/internal/config/rules/system_rules_test.go @@ -677,8 +677,8 @@ func TestFileFilter_IsUserIncluded_EmptyInclude(t *testing.T) { func TestFileFilter_CaseInsensitive(t *testing.T) { f := &FileFilter{ - Include: []string{"src/**/*.java"}, - Exclude: []string{"**/generated/**"}, + Include: []string{"src/**/*.java", "**/CHANGELOG.md"}, + Exclude: []string{"**/generated/**", "README.md", "**/*.{Go,Java}"}, } if !f.IsUserIncluded("SRC/Main/Foo.Java") { @@ -687,6 +687,17 @@ func TestFileFilter_CaseInsensitive(t *testing.T) { if !f.IsUserExcluded("SRC/Generated/Api.java") { t.Errorf("expected case-insensitive exclude match") } + + // Verify patterns containing uppercase letters also match. + if !f.IsUserIncluded("docs/CHANGELOG.md") { + t.Errorf("expected uppercase include pattern to match case-insensitively") + } + if !f.IsUserExcluded("README.md") { + t.Errorf("expected uppercase exclude pattern to match case-insensitively") + } + if !f.IsUserExcluded("pkg/Main.JAVA") { + t.Errorf("expected brace-expanded uppercase pattern to match case-insensitively") + } } func TestNewResolver_FileFilterMerged(t *testing.T) {