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

Open
rsc opened this issue Oct 25, 2018 · 4 comments

Comments

Projects
None yet
7 participants
@rsc
Copy link
Contributor

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

@tandr

This comment has been minimized.

Copy link

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 modified the milestones: Go1.12, Go1.13 Jan 17, 2019

@bcmills bcmills added the modules label Jan 17, 2019

@jayconrod

This comment has been minimized.

Copy link
Contributor

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.

@wselwood

This comment has been minimized.

Copy link
Contributor

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 github.com/satappscatapult/warmconsidering/: cannot find module for path github.com/satappscatapult/warmconsidering/message

which is mighty confusing

series of comands

go mod init github.com/satelliteapplicationscatapult/warmconsidering/
code .
# write some things and create a submodule
go build
build github.com/satappscatapult/warmconsidering/: cannot find module for path github.com/satappscatapult/warmconsidering/message

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

@gopherbot

This comment has been minimized.

Copy link

commented Jun 23, 2019

Change https://golang.org/cl/182560 mentions this issue: cmd/go: validate path in mod init path

gopherbot pushed a commit that referenced this issue Jun 25, 2019

cmd/go: validate path in mod init path
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
Reviewed-on: https://go-review.googlesource.com/c/go/+/182560
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.