Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: reject module path beginning with slash #28389

rsc opened this issue Oct 25, 2018 · 5 comments

cmd/go: reject module path beginning with slash #28389

rsc opened this issue Oct 25, 2018 · 5 comments
modules NeedsFix


Copy link

@rsc rsc commented Oct 25, 2018

Re #28336, we should

  1. Reject go mod init /absolute/path.
  2. Refuse to load any go.mod that says module /absolute/path.

If we'd done either of those (we should do both), then the confusing build errors in #28336 would not have happened.

@rsc rsc added this to the Go1.12 milestone Oct 25, 2018
Copy link

@tandr tandr commented Oct 25, 2018

To me it seems that denying full path in mod init would be counterproductive for people willing (or have no choice but) to specify a full path because thats how they have their build system set up

I would not be surprised to see this in a bootstrap script

go mod init /bigdisk/buildmount/$USER/$REPO/some/path

@bcmills bcmills removed this from the Go1.12 milestone Jan 17, 2019
@bcmills bcmills added this to the Go1.13 milestone Jan 17, 2019
Copy link

@jayconrod jayconrod commented Feb 26, 2019

For reference, cmd/go/internal/module.CheckPath is the function go get uses to validate module paths. It performs a number of checks, not just for leading slashes.

In tests, I think we're using module paths that don't satisfy this check (e.g., the module path is a single word without a .). It's likely other people are taking advantage of this as well, both in tests and in monorepos that are never fetched with go get.

Copy link

@emilyselwood emilyselwood commented Feb 27, 2019

Trailing slashes should probably also be blocked. It works as long as you don't have sub packages. As soon as you try to import a sub package you get errors like
build cannot find module for path

which is mighty confusing

series of comands

go mod init
code .
# write some things and create a submodule
go build
build cannot find module for path

edit the go.mod file to remove the trailing slash from the build starts to work as expected.

@bcmills bcmills self-assigned this Feb 27, 2019
@bcmills bcmills added the NeedsFix label Feb 28, 2019
Copy link

@gopherbot gopherbot commented Jun 23, 2019

Change mentions this issue: cmd/go: validate path in mod init path

gopherbot pushed a commit that referenced this issue Jun 25, 2019
When mod init with given module path, validate that module path is a
valid import path.

Note that module.CheckImportPath is used, because module.CheckPath
verifies that module path is something that "go get" can fetch, which is
strictly stronger condition than "a valid module path".

Updates #28389
Fixes #32644

Change-Id: Ia60f218dd7d79186f87be723c28a96d6cb63017e
Run-TryBot: Cuong Manh Le <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Bryan C. Mills <>
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@andybons andybons added this to the Go1.14 milestone Jul 8, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
Copy link

@seankhliao seankhliao commented Jun 15, 2022

This is now rejected with go: malformed module path "/example": empty path element in both cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
modules NeedsFix
None yet

No branches or pull requests

8 participants