Skip to content

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

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

Closed
rsc opened this issue Oct 25, 2018 · 5 comments
Closed

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

rsc opened this issue Oct 25, 2018 · 5 comments
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

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
@tandr
Copy link

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

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.

@emilyselwood
Copy link
Contributor

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 The path to resolution is known, but the work has not been done. label Feb 28, 2019
@gopherbot
Copy link
Contributor

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
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
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@seankhliao
Copy link
Member

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

@rsc rsc unassigned bcmills Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants