Skip to content

Commit

Permalink
fix: 2179 jar chokes empty lines (#2254)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
spiffcs committed Oct 24, 2023
1 parent 73d5852 commit cd53092
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions syft/pkg/cataloger/java/parse_java_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
line := scanner.Text()

// empty lines denote section separators
if strings.TrimSpace(line) == "" {
if line == "" {
// we don't want to allocate a new section map that won't necessarily be used, do that once there is
// a non-empty line to process

Expand All @@ -46,7 +46,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
// this is a continuation

if lastKey == "" {
log.Warnf("java manifest %q: found continuation with no previous key: %q", path, line)
log.Debugf("java manifest %q: found continuation with no previous key: %q", path, line)
continue
}

Expand All @@ -58,7 +58,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
// this is a new key-value pair
idx := strings.Index(line, ":")
if idx == -1 {
log.Warnf("java manifest %q: unable to split java manifest key-value pairs: %q", path, line)
log.Debugf("java manifest %q: unable to split java manifest key-value pairs: %q", path, line)
continue
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
// per the manifest spec (https://docs.oracle.com/en/java/javase/11/docs/specs/jar/jar.html#jar-manifest)
// this should never happen. If it does, we want to know about it, but not necessarily stop
// cataloging entirely... for this reason we only log.
log.Warnf("java manifest section found without a name: %s", path)
log.Debugf("java manifest section found without a name: %s", path)
name = strconv.Itoa(i)
} else {
delete(s, "Name")
Expand Down
11 changes: 11 additions & 0 deletions syft/pkg/cataloger/java/parse_java_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ func TestParseJavaManifest(t *testing.T) {
},
},
},
{
// regression test, we should not trim space and choke of empty space
// https://github.com/anchore/syft/issues/2179
fixture: "test-fixtures/manifest/leading-space",
expected: pkg.JavaManifest{
Main: map[string]string{
"Key-keykeykey": "initialconfig:com$ # aka not empty line",
"should": "parse",
},
},
},
}

for _, test := range tests {
Expand Down
5 changes: 5 additions & 0 deletions syft/pkg/cataloger/java/test-fixtures/manifest/leading-space
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Key-keykeykey: initialconfig:com
continue line1,$
continue line1,$
$ # aka not empty line
should: parse

0 comments on commit cd53092

Please sign in to comment.