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: go:embed fails with special characters in module parent directory #53314

Closed
ryanjoneil opened this issue Jun 9, 2022 · 2 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ryanjoneil
Copy link

ryanjoneil commented Jun 9, 2022

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

$ go version
go version go1.18.3 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
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOVERSION="go1.18.3"

What did you do?

I have a simple file structure for a main package under a directory foo.

% tree foo
foo
└── example
    ├── baz.txt
    ├── go.mod
    └── main.go

go.mod is just the model name and Go version.

module example

go 1.18

The main.go embeds baz.txt and prints its contents.

package main

import (
	_ "embed"
	"fmt"
)

//go:embed baz.txt
var baz string

func main() {
	fmt.Println(baz)
}

baz.txt contains a simple string,

xyzzy

This works as expected.

% cd foo/example/
example % go build
example % ./example 
xyzzy

If I change the parent directory of the module from foo to [foo], go build cannot find baz.txt.

example % cd ../../
% mv foo '[foo]'
% cd \[foo\]/example 
example % go build
main.go:8:12: pattern baz.txt: no matching files found

What did you expect to see?

I expected the same behavior in both cases (go build succeeding).

What did you see instead?

go build cannot resolve the embed if a parent directory of the module contains square brackets. It doesn't seem like this should matter, since it is outside the module itself and is a valid directory name.

@cherrymui cherrymui changed the title cmd/compile: go:embed fails with special characters in module parent directory cmd/go: go:embed fails with special characters in module parent directory Jun 9, 2022
@cherrymui cherrymui added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Jun 9, 2022
@cherrymui cherrymui added this to the Backlog milestone Jun 9, 2022
@cherrymui
Copy link
Member

There may be a restriction on the file path. But I couldn't find the documentation.

cc @rsc @bcmills

@gopherbot
Copy link

Change https://go.dev/cl/411696 mentions this issue: cmd/go: quote package directory when calling glob

@golang golang locked and limited conversation to collaborators Jun 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants