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
}
+5 -1
View File
@@ -116,6 +116,10 @@ func TestZipFileManifest_GlobMatch(t *testing.T) {
"*/a-file.txt",
"some-dir/a-file.txt",
},
{
"*/A-file.txt",
"some-dir/a-file.txt",
},
{
"**/*.zip",
"nested.zip",
@@ -126,7 +130,7 @@ func TestZipFileManifest_GlobMatch(t *testing.T) {
t.Run(tc.glob, func(t *testing.T) {
glob := tc.glob
results := z.GlobMatch(glob)
results := z.GlobMatch(true, glob)
if len(results) == 1 && results[0] == tc.expected {
return
-1
View File
@@ -20,7 +20,6 @@ func FileNames() []string {
"LICENSE",
"LICENSE.md",
"LICENSE.markdown",
"license.txt",
"LICENSE.txt",
"LICENSE-2.0.txt",
"LICENCE-2.0.txt",