check for multiple delimiters when parsing pom properties

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-03-20 08:00:08 -04:00
parent c828e47765
commit 2f8a568d4f
No known key found for this signature in database
GPG key ID: 5CB45AE22BAB7EA7
8 changed files with 68 additions and 9 deletions

View file

@ -104,7 +104,7 @@ func (c *GenericCataloger) catalog(contents map[source.Location]io.ReadCloser) (
entries, err := parser(location.RealPath, content)
if err != nil {
// 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
}

View file

@ -24,7 +24,7 @@ func parsePomProperties(path string, reader io.Reader) (*pkg.PomProperties, erro
continue
}
idx := strings.Index(line, "=")
idx := strings.IndexAny(line, "=:")
if idx == -1 {
return nil, fmt.Errorf("unable to split pom.properties key-value pairs: %q", line)
}

View file

@ -11,11 +11,9 @@ import (
func TestParseJavaPomProperties(t *testing.T) {
tests := []struct {
fixture string
expected pkg.PomProperties
}{
{
fixture: "test-fixtures/pom/small.pom.properties",
expected: pkg.PomProperties{
Path: "test-fixtures/pom/small.pom.properties",
GroupID: "org.anchore",
@ -25,7 +23,6 @@ func TestParseJavaPomProperties(t *testing.T) {
},
},
{
fixture: "test-fixtures/pom/extra.pom.properties",
expected: pkg.PomProperties{
Path: "test-fixtures/pom/extra.pom.properties",
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 {
t.Run(test.fixture, func(t *testing.T) {
fixture, err := os.Open(test.fixture)
t.Run(test.expected.Path, func(t *testing.T) {
fixture, err := os.Open(test.expected.Path)
if err != nil {
t.Fatalf("could not open fixture: %+v", err)
}

View file

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

View file

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

View file

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

View file

@ -1,5 +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
artifactId= example-java-app-maven
version= 0.1.0

View file

@ -1,6 +1,8 @@
package source
import (
"fmt"
"github.com/anchore/syft/internal/log"
"github.com/anchore/stereoscope/pkg/file"
@ -42,3 +44,21 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
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)
}