Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion syft/pkg/cataloger/java/parse_pom_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ func resolveProperty(pom gopom.Project, property *string, propertyName string) s
seenBeforePropertyNames := map[string]struct{}{
propertyName: {},
}
return recursiveResolveProperty(pom, propertyCase, seenBeforePropertyNames)
result := recursiveResolveProperty(pom, propertyCase, seenBeforePropertyNames)
if propertyMatcher.MatchString(result) {
return "" // dereferencing variable failed; fall back to empty string
}
return result
}

//nolint:gocognit
Expand Down
19 changes: 11 additions & 8 deletions syft/pkg/cataloger/java/parse_pom_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func Test_resolveProperty(t *testing.T) {
pom: gopom.Project{
Parent: nil,
},
expected: "${project.parent.groupId}",
expected: "",
},
{
name: "nil string pointer halts search",
Expand All @@ -512,7 +512,7 @@ func Test_resolveProperty(t *testing.T) {
GroupID: nil,
},
},
expected: "${project.parent.groupId}",
expected: "",
},
{
name: "double dereference",
Expand All @@ -537,7 +537,7 @@ func Test_resolveProperty(t *testing.T) {
Version: stringPointer("1.2.3"),
},
},
expected: "${springboot.version}",
expected: "",
},
{
name: "resolution halts even if it resolves to a variable",
Expand All @@ -552,7 +552,7 @@ func Test_resolveProperty(t *testing.T) {
},
},
},
expected: "${undefined.version}",
expected: "",
},
{
name: "resolution halts even if cyclic",
Expand All @@ -564,7 +564,7 @@ func Test_resolveProperty(t *testing.T) {
},
},
},
expected: "${springboot.version}",
expected: "",
},
{
name: "resolution halts even if cyclic more steps",
Expand All @@ -578,21 +578,24 @@ func Test_resolveProperty(t *testing.T) {
},
},
},
expected: "${cyclic.version}",
expected: "",
},
{
name: "resolution halts even if cyclic involving parent",
property: "${cyclic.version}",
pom: gopom.Project{
Parent: &gopom.Parent{
Version: stringPointer("${cyclic.version}"),
},
Properties: &gopom.Properties{
Entries: map[string]string{
"other.version": "${cyclic.version}",
"other.version": "${parent.version}",
"springboot.version": "${other.version}",
"cyclic.version": "${springboot.version}",
},
},
},
expected: "${cyclic.version}",
expected: "",
},
}

Expand Down