mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
prefer warning over erroring out when parsing java manifests (#688)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
85ac5bcbf8
commit
727b84ce0d
@ -46,7 +46,8 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
|
|||||||
// this is a continuation
|
// this is a continuation
|
||||||
|
|
||||||
if lastKey == "" {
|
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)
|
sections[currentSection()][lastKey] += strings.TrimSpace(line)
|
||||||
@ -54,21 +55,26 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if lastKey == "" {
|
|
||||||
// we're entering a new section
|
|
||||||
|
|
||||||
sections = append(sections, make(map[string]string))
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a new key-value pair
|
// this is a new key-value pair
|
||||||
idx := strings.Index(line, ":")
|
idx := strings.Index(line, ":")
|
||||||
if idx == -1 {
|
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])
|
key := strings.TrimSpace(line[0:idx])
|
||||||
value := strings.TrimSpace(line[idx+1:])
|
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
|
sections[currentSection()][key] = value
|
||||||
|
|
||||||
// keep track of key for potential future continuations
|
// keep track of key for potential future continuations
|
||||||
|
|||||||
@ -70,6 +70,15 @@ func TestParseJavaManifest(t *testing.T) {
|
|||||||
"thing-1": {
|
"thing-1": {
|
||||||
"Built-By": "?",
|
"Built-By": "?",
|
||||||
},
|
},
|
||||||
|
"thing-2": {
|
||||||
|
"Built-By": "someone!",
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"Other": "things",
|
||||||
|
},
|
||||||
|
"3": {
|
||||||
|
"Last": "item",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -5,3 +5,18 @@ Created-By: Apache Maven 3.6.3
|
|||||||
|
|
||||||
Name: thing-1
|
Name: thing-1
|
||||||
Built-By: ?
|
Built-By: ?
|
||||||
|
|
||||||
|
.
|
||||||
|
|
||||||
|
Name: thing-2
|
||||||
|
Built-By: someone!
|
||||||
|
|
||||||
|
|
||||||
|
:
|
||||||
|
|
||||||
|
Other: things
|
||||||
|
junk
|
||||||
|
|
||||||
|
:
|
||||||
|
|
||||||
|
Last: item
|
||||||
Loading…
x
Reference in New Issue
Block a user