feat: Perform case insensitive matching on Java license files (#2235)

Signed-off-by: Colm O hEigeartaigh <coheigea@apache.org>
This commit is contained in:
Colm O hEigeartaigh
2023-10-25 09:51:59 -04:00
committed by GitHub
parent 7392d607b6
commit 1daf18fee9
4 changed files with 22 additions and 13 deletions
+9 -3
View File
@@ -40,15 +40,18 @@ func (z ZipFileManifest) Add(entry string, info os.FileInfo) {
}
// GlobMatch returns the path keys that match the given value(s).
func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
func (z ZipFileManifest) GlobMatch(caseInsensitive bool, patterns ...string) []string {
uniqueMatches := strset.New()
for _, pattern := range patterns {
for entry := range z {
// We want to match globs as if entries begin with a leading slash (akin to an absolute path)
// so that glob logic is consistent inside and outside of ZIP archives
normalizedEntry := normalizeZipEntryName(entry)
normalizedEntry := normalizeZipEntryName(caseInsensitive, entry)
if caseInsensitive {
pattern = strings.ToLower(pattern)
}
if GlobMatch(pattern, normalizedEntry) {
uniqueMatches.Add(entry)
}
@@ -62,7 +65,10 @@ func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
}
// normalizeZipEntryName takes the given path entry and ensures it is prefixed with "/".
func normalizeZipEntryName(entry string) string {
func normalizeZipEntryName(caseInsensitive bool, entry string) string {
if caseInsensitive {
entry = strings.ToLower(entry)
}
if !strings.HasPrefix(entry, "/") {
return "/" + entry
}