Skip to content

Commit afe80cf

Browse files
committed
cmd/go/internal/modfetch: avoid using non-canonical semver tags
We insist that semver tags in repos be fully spelled out, as required by semver: v1.2.0, not v1.2. In other places, like go.mod, we do allow saying v1.2 as shorthand for v1.2.0. Don't confuse the issue by reporting a "v1.2" tag in the version list, since it's unaddressable. (If you type v1.2 vgo will look for v1.2.0.) Similarly, don't report tags that don't match the module path, and don't report tags that look like pseudo-versions. Additional fix for golang/go#23954, golang/go#24476. Change-Id: Iaac0fb36362b25e5faef5271c110d432ec04bc8b Reviewed-on: https://go-review.googlesource.com/107659 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 77e0cc2 commit afe80cf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

vendor/cmd/go/internal/modfetch/coderepo.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r *codeRepo) Versions(prefix string) ([]string, error) {
7979
if err != nil {
8080
return nil, err
8181
}
82-
var list []string
82+
list := []string{}
8383
for _, tag := range tags {
8484
if !strings.HasPrefix(tag, p) {
8585
continue
@@ -88,11 +88,7 @@ func (r *codeRepo) Versions(prefix string) ([]string, error) {
8888
if r.codeDir != "" {
8989
v = v[len(r.codeDir)+1:]
9090
}
91-
// Only accept canonical semver tags from the repo. (See #24476.)
92-
if v != semver.Canonical(v) {
93-
continue
94-
}
95-
if !module.MatchPathMajor(v, r.pathMajor) {
91+
if !semver.IsValid(v) || v != semver.Canonical(v) || isPseudoVersion(v) || !module.MatchPathMajor(v, r.pathMajor) {
9692
continue
9793
}
9894
list = append(list, v)

vendor/cmd/go/internal/modfetch/coderepo_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ var codeRepoVersionsTests = []struct {
505505
path: "gopkg.in/russross/blackfriday.v2",
506506
versions: []string{"v1.0.0-gopkgin-v2.0.0"},
507507
},
508+
{
509+
path: "gopkg.in/natefinch/lumberjack.v2",
510+
versions: []string{},
511+
},
508512
}
509513

510514
func TestCodeRepoVersions(t *testing.T) {

0 commit comments

Comments
 (0)