Skip to content

cmd/go: go mod init in GOPATH can create invalid module path #46085

Closed
@perillo

Description

@perillo

What version of Go are you using (go version)?

$ go version
go version go1.16.4 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE="*.local"
GOMODCACHE="/home/manlio/.local/lib/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="*.local"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3071205222=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.16.4 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.16.4
uname -sr: Linux 5.11.16-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) release release version 2.33.
gdb --version: GNU gdb (GDB) 10.1

What did you do?

Assuming $GOPATH is ~/go:

mkdir "~/go/src/test.localhost/space in dir"
cd "~/go/src/test.localhost/space in dir"
go mod init

What did you expect to see?

An error reported by go mod init, since the computed module path is incorrect.

What did you see instead?

$ cat go.mod
module "test.localhost/space in dir"

go 1.16

The issue is probably the same as the one in #45025, however in this case go mod is free to don't use the auto generated module path.

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on May 10, 2021
added this to the Backlog milestone on May 10, 2021
heschi

heschi commented on May 10, 2021

@heschi
Contributor
jayconrod

jayconrod commented on May 10, 2021

@jayconrod
Contributor

CL 288712 will probably fix this.

perillo

perillo commented on May 10, 2021

@perillo
ContributorAuthor

@jayconrod, you are right, thanks.

Looking at the source code, findModulePath returns the error bad module path inferred from directory in GOPATH in case of invalid module path. It calls checkModulePathLax.

I'm not closing this issue because https://go-review.googlesource.com/c/go/+/288712 don't have tests for this use case.

perillo

perillo commented on May 10, 2021

@perillo
ContributorAuthor

Looking at cmd/go/testdata/script/mod_init*, it seems there are no tests to cover the findModulePath function.

gopherbot

gopherbot commented on May 16, 2021

@gopherbot
Contributor

Change https://golang.org/cl/320310 mentions this issue: cmd/go: align checks of module path when creating go.mod file

gopherbot

gopherbot commented on Aug 13, 2021

@gopherbot
Contributor

Change https://golang.org/cl/288712 mentions this issue: cmd/go: make mod init disallow invalid major version suffixes

locked and limited conversation to collaborators on Aug 17, 2022
added a commit that references this issue on Apr 29, 2024
a2a9a7b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeGoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jayconrod@perillo@gopherbot@heschi

        Issue actions

          cmd/go: go mod init in GOPATH can create invalid module path · Issue #46085 · golang/go