mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
fix: update mainModuleVersion function to always prefix v to findings (#3087)
* chore: basic fix Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com> * test: make sure ldflags are prefixed with v --------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
@@ -180,6 +180,10 @@ func (c *goBinaryCataloger) makeGoMainPackage(resolver file.Resolver, mod *exten
|
||||
version := c.findMainModuleVersion(metadata, gbs, reader)
|
||||
|
||||
if version != "" {
|
||||
// make sure version is prefixed with v as some build systems parsed
|
||||
// during `findMainModuleVersion` can include incomplete semver
|
||||
// vx.x.x is correct
|
||||
version = ensurePrefix(version, "v")
|
||||
main.Version = version
|
||||
main.PURL = packageURL(main.Name, main.Version)
|
||||
|
||||
@@ -398,3 +402,10 @@ func createMainModuleFromPath(existing *extendedBuildInfo) debug.Module {
|
||||
Version: devel,
|
||||
}
|
||||
}
|
||||
|
||||
func ensurePrefix(s, prefix string) string {
|
||||
if !strings.HasPrefix(s, prefix) {
|
||||
return prefix + s
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user