diff --git a/syft/pkg/cataloger/java/parse_java_manifest.go b/syft/pkg/cataloger/java/parse_java_manifest.go index 784b6f9107c..7d9c7b7f621 100644 --- a/syft/pkg/cataloger/java/parse_java_manifest.go +++ b/syft/pkg/cataloger/java/parse_java_manifest.go @@ -46,7 +46,8 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error) // this is a continuation if lastKey == "" { - return nil, fmt.Errorf("found continuation with no previous key (%s)", line) + log.Warnf("java manifest %q: found continuation with no previous key: %q", path, line) + continue } sections[currentSection()][lastKey] += strings.TrimSpace(line) @@ -54,21 +55,26 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error) continue } - if lastKey == "" { - // we're entering a new section - - sections = append(sections, make(map[string]string)) - } - // this is a new key-value pair idx := strings.Index(line, ":") if idx == -1 { - return nil, fmt.Errorf("unable to split java manifest key-value pairs: %q", line) + log.Warnf("java manifest %q: unable to split java manifest key-value pairs: %q", path, line) + continue } key := strings.TrimSpace(line[0:idx]) value := strings.TrimSpace(line[idx+1:]) + if key == "" { + // don't attempt to add new keys or sections unless there is a non-empty key + continue + } + + if lastKey == "" { + // we're entering a new section + sections = append(sections, make(map[string]string)) + } + sections[currentSection()][key] = value // keep track of key for potential future continuations diff --git a/syft/pkg/cataloger/java/parse_java_manifest_test.go b/syft/pkg/cataloger/java/parse_java_manifest_test.go index e36cc2b1356..0982e35b2a3 100644 --- a/syft/pkg/cataloger/java/parse_java_manifest_test.go +++ b/syft/pkg/cataloger/java/parse_java_manifest_test.go @@ -70,6 +70,15 @@ func TestParseJavaManifest(t *testing.T) { "thing-1": { "Built-By": "?", }, + "thing-2": { + "Built-By": "someone!", + }, + "2": { + "Other": "things", + }, + "3": { + "Last": "item", + }, }, }, }, diff --git a/syft/pkg/cataloger/java/test-fixtures/manifest/extra-empty-lines b/syft/pkg/cataloger/java/test-fixtures/manifest/extra-empty-lines index 5c68a7d7b74..4f89731ff09 100644 --- a/syft/pkg/cataloger/java/test-fixtures/manifest/extra-empty-lines +++ b/syft/pkg/cataloger/java/test-fixtures/manifest/extra-empty-lines @@ -5,3 +5,18 @@ Created-By: Apache Maven 3.6.3 Name: thing-1 Built-By: ? + +. + +Name: thing-2 +Built-By: someone! + + + : + +Other: things +junk + +: + +Last: item \ No newline at end of file