Skip to content

Commit 5cd4436

Browse files
committed
internal/postgres: exclude internal packages when doing shortcut resolution
pkgsite allows users to use a shortcut when looking up std packages. For example, pkg.go.dev/http will resolve to pkg.go.dev/net/http. Currently, this shortcut resolution also works for internal packages (e.g. pkg.go.dev/boring will resolve to pkg.go.dev/crypto/internal/boring), even though Go users would likely not care about internal packages. An unfortunate side-effect of this is that our shortcut resolution does not work for packages which has a similarly-named internal package: pkg.go.dev/synctest does not resolve to pkg.go.dev/testing/synctest as the existence of pkg.go.dev/internal/synctest makes the resolution ambiguous. This change updates our shortcut resolution logic to exclude all internal packages. For golang/go#76136 Change-Id: I83fcf32861079d051bc8dc3be29092480d53f667 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/717840 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> kokoro-CI: kokoro <[email protected]> Reviewed-by: Nicholas Husin <[email protected]>
1 parent 950d5ec commit 5cd4436

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

internal/frontend/fetchserver/server_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ var testModules = []testModule{
161161
name: "http",
162162
suffix: "net/http",
163163
},
164+
{
165+
name: "boring",
166+
suffix: "crypto/internal/boring",
167+
},
168+
{
169+
name: "asan",
170+
suffix: "internal/asan",
171+
},
164172
},
165173
},
166174
{
@@ -686,6 +694,16 @@ func serverTestCases() []serverTestCase {
686694
wantStatusCode: http.StatusMovedPermanently,
687695
wantLocation: "/[email protected]",
688696
},
697+
{
698+
name: "stdlib top-level internal shortcut (internal/asan)",
699+
urlPath: "/asan",
700+
wantStatusCode: http.StatusNotFound,
701+
},
702+
{
703+
name: "stdlib internal shortcut (crypto/internal/boring)",
704+
urlPath: "/boring",
705+
wantStatusCode: http.StatusNotFound,
706+
},
689707
{
690708
name: "package page with trailiing slash",
691709
urlPath: "/github.com/my/module/",

internal/postgres/stdlib.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
// the path must end with "/" + suffix.
1818
//
1919
// We are only interested in actual standard library packages: not commands, which we happen to include
20-
// in the stdlib module, and not directories (paths that do not contain a package).
20+
// in the stdlib module; not directories (paths that do not contain a package); and not internal
21+
// packages.
2122
func (db *DB) GetStdlibPathsWithSuffix(ctx context.Context, suffix string) (paths []string, err error) {
2223
defer derrors.WrapStack(&err, "DB.GetStdlibPaths(ctx, %q)", suffix)
2324

@@ -37,6 +38,8 @@ func (db *DB) GetStdlibPathsWithSuffix(ctx context.Context, suffix string) (path
3738
LIMIT 1)
3839
AND u.name != ''
3940
AND p.path NOT LIKE 'cmd/%'
41+
AND p.path NOT LIKE 'internal/%'
42+
AND p.path NOT LIKE '%/internal/%'
4043
AND p.path LIKE '%/' || $2
4144
ORDER BY p.path
4245
`

0 commit comments

Comments
 (0)