From 2d37d0372c26bde78d5b76681b35150eeac2121f Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 7 Mar 2024 09:49:19 +0600 Subject: [PATCH] fix: check artifactID prefix when getting version from fileName --- pkg/crawler/crawler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/crawler/crawler.go b/pkg/crawler/crawler.go index 95f672a..29f3ee7 100644 --- a/pkg/crawler/crawler.go +++ b/pkg/crawler/crawler.go @@ -208,9 +208,9 @@ func (c *Crawler) crawlSHA1(ctx context.Context, baseURL string, meta *Metadata, if err != nil { return xerrors.Errorf("unable to fetch sha1: %s", err) } - if len(sha1) != 0 { + if ver := versionFromSha1URL(meta.ArtifactID, sha1URL); ver != "" && len(sha1) != 0 { v := Version{ - Version: versionFromSha1URL(meta.ArtifactID, sha1URL), + Version: ver, SHA1: sha1, } versions = append(versions, v) @@ -348,5 +348,8 @@ func (c *Crawler) fetchSHA1(ctx context.Context, url string) ([]byte, error) { func versionFromSha1URL(artifactId, sha1URL string) string { ss := strings.Split(sha1URL, "/") fileName := ss[len(ss)-1] + if !strings.HasPrefix(fileName, artifactId) { + return "" + } return strings.TrimSuffix(strings.TrimPrefix(fileName, artifactId+"-"), ".jar.sha1") }