internal/stdlib: fix versions pages for packages only in master
Fixes golang/go#58594.
Change-Id: I13c9879a12ae070d1aa07d8e152bafa07cfb7952
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/474536
TryBot-Result: kokoro <noreply+kokoro@google.com>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/internal/frontend/versions.go b/internal/frontend/versions.go
index 161ab78..454e242 100644
--- a/internal/frontend/versions.go
+++ b/internal/frontend/versions.go
@@ -114,7 +114,7 @@
}
return constructUnitURL(versionPath, mi.ModulePath, linkVersion(mi.ModulePath, mi.Version, mi.Version))
}
- return buildVersionDetails(ctx, um.ModulePath, um.Path, versions, sh, linkify, vc), nil
+ return buildVersionDetails(ctx, um.ModulePath, um.Path, versions, sh, linkify, vc)
}
// pathInVersion constructs the full import path of the package corresponding
@@ -147,7 +147,7 @@
sh *internal.SymbolHistory,
linkify func(v *internal.ModuleInfo) string,
vc *vuln.Client,
-) *VersionsDetails {
+) (*VersionsDetails, error) {
// lists organizes versions by VersionListKey.
lists := make(map[VersionListKey]*VersionList)
// seenLists tracks the order in which we encounter entries of each version
@@ -162,7 +162,7 @@
var err error
major, err = stdlib.MajorVersionForVersion(mi.Version)
if err != nil {
- panic(err)
+ return nil, err
}
}
// We prefer the path major version except for v1 import paths where the
@@ -234,7 +234,18 @@
}
// Sort for testing.
sort.Strings(details.OtherModules)
- return &details
+
+ // Pkgsite will not display psuedoversions for the standard library. If the
+ // version details contain master then this package exists only at master.
+ // Show only the first entry. The additional entries will all be duplicate
+ // links to package@master.
+ if len(details.ThisModule) > 0 &&
+ len(details.ThisModule[0].Versions) > 0 &&
+ currentModulePath == stdlib.ModulePath &&
+ details.ThisModule[0].Versions[0].Version == "master" {
+ details.ThisModule[0].Versions = details.ThisModule[0].Versions[:1]
+ }
+ return &details, nil
}
// isMinor reports whether v is a release version where the patch version is 0.
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go
index cf0d155..b7fa93b 100644
--- a/internal/stdlib/stdlib.go
+++ b/internal/stdlib/stdlib.go
@@ -152,8 +152,8 @@
if err != nil {
return "", err
}
- if tag == "go1" {
- return tag, nil
+ if tag == "go1" || tag == "master" {
+ return "go1", nil
}
i := strings.IndexRune(tag, '.')
if i < 0 {
diff --git a/internal/stdlib/stdlib_test.go b/internal/stdlib/stdlib_test.go
index 7cd43aa..7297582 100644
--- a/internal/stdlib/stdlib_test.go
+++ b/internal/stdlib/stdlib_test.go
@@ -112,6 +112,8 @@
{"v1.13.3", "go1"},
{"v1.9.0-rc.2", "go1"},
{"v2.1.3", "go2"},
+ {"v2.1.3", "go2"},
+ {"v0.0.0-20230307225218-457fd1d52d17", "go1"},
} {
got, err := MajorVersionForVersion(test.in)
if (err != nil) != (test.want == "") {