mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 17:03:17 +01:00
check for multiple delimiters when parsing pom properties
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
c828e47765
commit
2f8a568d4f
@ -104,7 +104,7 @@ func (c *GenericCataloger) catalog(contents map[source.Location]io.ReadCloser) (
|
|||||||
entries, err := parser(location.RealPath, content)
|
entries, err := parser(location.RealPath, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: should we fail? or only log?
|
// TODO: should we fail? or only log?
|
||||||
log.Warnf("cataloger '%s' failed to parse entries (location=%+v): %+v", c.upstreamCataloger, location, err)
|
log.Warnf("cataloger '%s' failed to parse entries (%+v): %+v", c.upstreamCataloger, location, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ func parsePomProperties(path string, reader io.Reader) (*pkg.PomProperties, erro
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
idx := strings.Index(line, "=")
|
idx := strings.IndexAny(line, "=:")
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
return nil, fmt.Errorf("unable to split pom.properties key-value pairs: %q", line)
|
return nil, fmt.Errorf("unable to split pom.properties key-value pairs: %q", line)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,11 +11,9 @@ import (
|
|||||||
|
|
||||||
func TestParseJavaPomProperties(t *testing.T) {
|
func TestParseJavaPomProperties(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
fixture string
|
|
||||||
expected pkg.PomProperties
|
expected pkg.PomProperties
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
fixture: "test-fixtures/pom/small.pom.properties",
|
|
||||||
expected: pkg.PomProperties{
|
expected: pkg.PomProperties{
|
||||||
Path: "test-fixtures/pom/small.pom.properties",
|
Path: "test-fixtures/pom/small.pom.properties",
|
||||||
GroupID: "org.anchore",
|
GroupID: "org.anchore",
|
||||||
@ -25,7 +23,6 @@ func TestParseJavaPomProperties(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fixture: "test-fixtures/pom/extra.pom.properties",
|
|
||||||
expected: pkg.PomProperties{
|
expected: pkg.PomProperties{
|
||||||
Path: "test-fixtures/pom/extra.pom.properties",
|
Path: "test-fixtures/pom/extra.pom.properties",
|
||||||
GroupID: "org.anchore",
|
GroupID: "org.anchore",
|
||||||
@ -38,11 +35,38 @@ func TestParseJavaPomProperties(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
expected: pkg.PomProperties{
|
||||||
|
Path: "test-fixtures/pom/colon-delimited.pom.properties",
|
||||||
|
GroupID: "org.anchore",
|
||||||
|
ArtifactID: "example-java-app-maven",
|
||||||
|
Version: "0.1.0",
|
||||||
|
Extra: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expected: pkg.PomProperties{
|
||||||
|
Path: "test-fixtures/pom/equals-delimited-with-colons.pom.properties",
|
||||||
|
GroupID: "org.anchore",
|
||||||
|
ArtifactID: "example-java:app-maven",
|
||||||
|
Version: "0.1.0:something",
|
||||||
|
Extra: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expected: pkg.PomProperties{
|
||||||
|
Path: "test-fixtures/pom/colon-delimited-with-equals.pom.properties",
|
||||||
|
GroupID: "org.anchore",
|
||||||
|
ArtifactID: "example-java=app-maven",
|
||||||
|
Version: "0.1.0=something",
|
||||||
|
Extra: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.fixture, func(t *testing.T) {
|
t.Run(test.expected.Path, func(t *testing.T) {
|
||||||
fixture, err := os.Open(test.fixture)
|
fixture, err := os.Open(test.expected.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not open fixture: %+v", err)
|
t.Fatalf("could not open fixture: %+v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
#Generated by Maven
|
||||||
|
#Tue Jul 07 18:59:56 GMT 2020
|
||||||
|
groupId:org.anchore
|
||||||
|
artifactId: example-java=app-maven
|
||||||
|
version: 0.1.0=something
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
#Generated by Maven
|
||||||
|
#Tue Jul 07 18:59:56 GMT 2020
|
||||||
|
groupId:org.anchore
|
||||||
|
artifactId: example-java-app-maven
|
||||||
|
version: 0.1.0
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
#Generated by Maven
|
||||||
|
#Tue Jul 07 18:59:56 GMT 2020
|
||||||
|
groupId=org.anchore
|
||||||
|
artifactId= example-java:app-maven
|
||||||
|
version= 0.1.0:something
|
||||||
@ -1,6 +1,8 @@
|
|||||||
package source
|
package source
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/log"
|
"github.com/anchore/syft/internal/log"
|
||||||
|
|
||||||
"github.com/anchore/stereoscope/pkg/file"
|
"github.com/anchore/stereoscope/pkg/file"
|
||||||
@ -42,3 +44,21 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
|
|||||||
ref: ref,
|
ref: ref,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l Location) String() string {
|
||||||
|
str := ""
|
||||||
|
if l.ref.ID() != 0 {
|
||||||
|
str += fmt.Sprintf("id=%d ", l.ref.ID())
|
||||||
|
}
|
||||||
|
|
||||||
|
str += fmt.Sprintf("RealPath=%q", l.RealPath)
|
||||||
|
|
||||||
|
if l.VirtualPath != "" {
|
||||||
|
str += fmt.Sprintf(" VirtualPath=%q", l.VirtualPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if l.FileSystemID != "" {
|
||||||
|
str += fmt.Sprintf(" Layer=%q", l.FileSystemID)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Location<%s>", str)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user