prefer warning over erroring out when parsing java manifests (#688)

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-12-14 12:17:05 -05:00 committed by GitHub
parent 85ac5bcbf8
commit 727b84ce0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 8 deletions

View File

@ -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

View File

@ -70,6 +70,15 @@ func TestParseJavaManifest(t *testing.T) {
"thing-1": {
"Built-By": "?",
},
"thing-2": {
"Built-By": "someone!",
},
"2": {
"Other": "things",
},
"3": {
"Last": "item",
},
},
},
},

View File

@ -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