Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions syft/pkg/cataloger/java/parse_java_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,35 @@ 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)

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
Expand Down
9 changes: 9 additions & 0 deletions syft/pkg/cataloger/java/parse_java_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func TestParseJavaManifest(t *testing.T) {
"thing-1": {
"Built-By": "?",
},
"thing-2": {
"Built-By": "someone!",
},
"2": {
"Other": "things",
},
"3": {
"Last": "item",
},
},
},
},
Expand Down
15 changes: 15 additions & 0 deletions syft/pkg/cataloger/java/test-fixtures/manifest/extra-empty-lines
Original file line number Diff line number Diff line change
Expand Up @@ -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