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: modules are rejected if any filename has a trailing . #62411

Closed
chinmayb opened this issue Sep 1, 2023 · 3 comments
Closed

cmd/go: modules are rejected if any filename has a trailing . #62411

chinmayb opened this issue Sep 1, 2023 · 3 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Milestone

Comments

@chinmayb
Copy link

chinmayb commented Sep 1, 2023

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

$ go version
 go1.20.4 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/cbharadwaj/Library/Caches/go-build"
GOENV="/Users/cbharadwaj/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/cbharadwaj/go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/cbharadwaj/go/"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.20.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.20.4/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_7/_s_vtxzs0_vc5v4gj005cbg40000gp/T/go-build1866445795=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Trying to import a package using go mod tidy that contains a test file containing trailer .

https://github.com/chinmayb/notepad/blob/v0.0.1/pkg/default.test.

Trying to import /pkg elsewhere results in error

What did you expect to see?

No error and ignore non go files for the trailing .

What did you see instead?

go mod tidy fails.

sample go.mod file

module test

go 1.19

require github.com/jinzhu/gorm v1.9.16

require (
  github.com/denisenkom/go-mssqldb v0.12.0 // indirect
  github.com/go-sql-driver/mysql v1.6.0 // indirect
  github.com/jinzhu/inflection v1.0.0 // indirect
  github.com/jinzhu/now v1.1.1 // indirect
  github.com/lib/pq v1.10.6 // indirect
  github.com/mattn/go-sqlite3 v1.14.10 // indirect
  golang.org/x/crypto v0.7.0 // indirect
  github.com/chinmayb/notepad v0.0.1
)

go mod tidy

Fails with below error

test imports
	**github.com/chinmayb/notepad/pkg/errorutil: create zip: pkg/default.test.: malformed file path "pkg/default.test.": trailing dot in path element**
test imports
	github.com/jinzhu/gorm tested by
	github.com/jinzhu/gorm.test imports
	github.com/erikstmartin/go-testdb: github.com/chinmayb/notepad@v0.0.1: verifying go.mod: github.com/chinmayb/notepad@v0.0.1/go.mod: reading https://sum.golang.org/lookup/github.com/chinmayb/notepad@v0.0.1: 404 Not Found
@dmitshur dmitshur changed the title go mod tidy errors with trailing dot in path element if any filename has a trailing . cmd/go: go mod tidy errors with trailing dot in path element if any filename has a trailing . Sep 1, 2023
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Sep 1, 2023
@dmitshur dmitshur added this to the Backlog milestone Sep 1, 2023
@dmitshur
Copy link
Contributor

dmitshur commented Sep 1, 2023

Thanks for reporting. Here's a smaller reproducer:

$ cd $(mktemp -d)
$ go mod init test
$ GOPATH=$(mktemp -d) GOPROXY=direct GOSUMDB=off go get github.com/chinmayb/notepad@v0.0.1
go: downloading github.com/chinmayb/notepad v0.0.1
go: github.com/chinmayb/notepad@v0.0.1: create zip: pkg/default.test.: malformed file path "pkg/default.test.": trailing dot in path element

The relevant constraints on file paths in modules are documented at https://go.dev/ref/mod#zip-path-size-constraints. I'm not immediately seeing why a file named "default.test." must be disallowed, but that appears to be the current behavior implemented by module.CheckFilePath (see https://go.dev/play/p/_0kVbNFSoxe).

CC @bcmills, @matloob.

@dmitshur dmitshur changed the title cmd/go: go mod tidy errors with trailing dot in path element if any filename has a trailing . cmd/go: modules are rejected if any filename has a trailing . Sep 1, 2023
@dmitshur
Copy link
Contributor

dmitshur commented Sep 1, 2023

Oh, it does seem to match the documented behavior. CheckFilePath docs say:

The definition of a valid file path is the same as the definition of a valid import path except that the set of allowed characters is larger [...]

And CheckImportPath docs say:

A valid path element is a non-empty string made up of ASCII letters, [...]. It must not end with a dot (U+002E) [...]

@bcmills
Copy link
Contributor

bcmills commented Sep 1, 2023

This is intentional, for portability — we must be able to unpack the module on any platform that supports Go, and the Windows file naming conventions (https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions) say in no uncertain terms: “Do not end a file or directory name with a space or a period.”

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Projects
None yet
Development

No branches or pull requests

3 participants