Skip to content

Commit

Permalink
cmd/go/internal/modfetch: avoid using non-canonical semver tags
Browse files Browse the repository at this point in the history
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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
  • Loading branch information
rsc committed Apr 25, 2018
1 parent 77e0cc2 commit afe80cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 2 additions & 6 deletions vendor/cmd/go/internal/modfetch/coderepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *codeRepo) Versions(prefix string) ([]string, error) {
if err != nil {
return nil, err
}
var list []string
list := []string{}
for _, tag := range tags {
if !strings.HasPrefix(tag, p) {
continue
Expand All @@ -88,11 +88,7 @@ func (r *codeRepo) Versions(prefix string) ([]string, error) {
if r.codeDir != "" {
v = v[len(r.codeDir)+1:]
}
// Only accept canonical semver tags from the repo. (See #24476.)
if v != semver.Canonical(v) {
continue
}
if !module.MatchPathMajor(v, r.pathMajor) {
if !semver.IsValid(v) || v != semver.Canonical(v) || isPseudoVersion(v) || !module.MatchPathMajor(v, r.pathMajor) {
continue
}
list = append(list, v)
Expand Down
4 changes: 4 additions & 0 deletions vendor/cmd/go/internal/modfetch/coderepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ var codeRepoVersionsTests = []struct {
path: "gopkg.in/russross/blackfriday.v2",
versions: []string{"v1.0.0-gopkgin-v2.0.0"},
},
{
path: "gopkg.in/natefinch/lumberjack.v2",
versions: []string{},
},
}

func TestCodeRepoVersions(t *testing.T) {
Expand Down

0 comments on commit afe80cf

Please sign in to comment.