fix: make FileFilter patterns case-insensitive (#859)
Some checks are pending
CI / test (push) Waiting to run
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Deploy Pages / deploy (push) Blocked by required conditions
Deploy Pages / build (push) Waiting to run

* fix: make file filter patterns case-insensitive

* test: strengthen case-insensitive file filter coverage
This commit is contained in:
Shivam 2026-08-13 16:13:47 +05:30 committed by GitHub
parent 0e5fab8152
commit 8ce52972cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View file

@ -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
}
}

View file

@ -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) {