mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
fix: 2179 jar chokes empty lines (#2254)
--------- Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
parent
73d5852119
commit
cd530924d0
@ -32,7 +32,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
|
|||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
|
||||||
// empty lines denote section separators
|
// 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
|
// 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
|
// a non-empty line to process
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
|
|||||||
// this is a continuation
|
// this is a continuation
|
||||||
|
|
||||||
if lastKey == "" {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
|
|||||||
// 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 {
|
||||||
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)
|
// 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
|
// 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.
|
// 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)
|
name = strconv.Itoa(i)
|
||||||
} else {
|
} else {
|
||||||
delete(s, "Name")
|
delete(s, "Name")
|
||||||
|
|||||||
@ -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 {
|
for _, test := range tests {
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
Key-keykeykey: initialconfig:com
|
||||||
|
continue line1,$
|
||||||
|
continue line1,$
|
||||||
|
$ # aka not empty line
|
||||||
|
should: parse
|
||||||
Loading…
x
Reference in New Issue
Block a user