Skip to content

Commit

Permalink
Perform case insensitive matching in GlobMatch
Browse files Browse the repository at this point in the history
Signed-off-by: Colm O hEigeartaigh <coheigea@apache.org>
  • Loading branch information
coheigea committed Oct 17, 2023
1 parent 144ed72 commit 8f09379
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/file/zip_file_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (z ZipFileManifest) Add(entry string, info os.FileInfo) {
z[entry] = info
}

// GlobMatch returns the path keys that match the given value(s).
// GlobMatch returns the path keys that match the given value(s). Performs case insensitive matching
func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
uniqueMatches := internal.NewStringSet()

Expand All @@ -48,7 +48,7 @@ func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
// so that glob logic is consistent inside and outside of ZIP archives
normalizedEntry := normalizeZipEntryName(entry)

if GlobMatch(pattern, normalizedEntry) {
if GlobMatch(strings.ToLower(pattern), normalizedEntry) {
uniqueMatches.Add(entry)
}
}
Expand All @@ -63,8 +63,8 @@ func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
// normalizeZipEntryName takes the given path entry and ensures it is prefixed with "/".
func normalizeZipEntryName(entry string) string {
if !strings.HasPrefix(entry, "/") {
return "/" + entry
return strings.ToLower("/" + entry)
}

return entry
return strings.ToLower(entry)
}
8 changes: 8 additions & 0 deletions internal/file/zip_file_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ func TestZipFileManifest_GlobMatch(t *testing.T) {
"*/a-file.txt",
"some-dir/a-file.txt",
},
{
"*/A-file.txt",
"some-dir/a-file.txt",
},
{
"*/a-file.txt",
"some-dir/A-file.txt",
},
{
"**/*.zip",
"nested.zip",
Expand Down
1 change: 0 additions & 1 deletion internal/licenses/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
"LICENSE",
"LICENSE.md",
"LICENSE.markdown",
"license.txt",
"LICENSE.txt",
"LICENSE-2.0.txt",
"LICENCE-2.0.txt",
Expand Down

0 comments on commit 8f09379

Please sign in to comment.