mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
fix: restore case-insensitive java globbing for licenses, version and nested jars
The `archiveEntries` refactor dropped `GlobMatch`'s case-insensitive flag, so with nested cataloging off (the default) three lookups that main matched regardless of case became case-sensitive: - license files under `/META-INF/*` and `/*` (`meta-inf/LICENSE` was missed) - `/version.properties` - the `**/*.jar`, `**/*.war` check behind the "nested archives not cataloged" unknown, so `LIB.JAR` slipped past it `archiveEntries` now has a `globFold` for those call sites. The zip side restores `GlobMatch(true, ...)`, and the resolver side matches case-folded over every entry, since resolver globs are case-sensitive. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -46,7 +46,7 @@ func (z ZipFileManifest) Add(entry string, info os.FileInfo) {
|
||||
}
|
||||
|
||||
// GlobMatch returns the path keys to files (not directories) 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 {
|
||||
@@ -58,7 +58,11 @@ func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
matches, err := doublestar.Match(pattern, normalizedEntry)
|
||||
if err != nil {
|
||||
@@ -78,7 +82,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
|
||||
}
|
||||
|
||||
@@ -122,6 +122,10 @@ func TestZipFileManifest_GlobMatch(t *testing.T) {
|
||||
"**/a-file.txt",
|
||||
[]string{"some-dir/a-file.txt"},
|
||||
},
|
||||
{
|
||||
"**/A-file.txt",
|
||||
[]string{"some-dir/a-file.txt"},
|
||||
},
|
||||
{
|
||||
"**/*.zip",
|
||||
[]string{"nested.zip"},
|
||||
@@ -132,7 +136,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)
|
||||
|
||||
require.ElementsMatch(t, tc.expected, results)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user