-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Proposal Details
//go:embed x/* currently will not embed filenames in the x subdirectory with a ' single-quote character in their filename, such as
x/tom's favorite file.txt
Single quote is not such a rare character that I think it should be outright rejected by embed. It would be useful if go:embed * could include filenames with a single-quote character in their name.
The globbed filenames are rejected based on the isBadEmbedName in pkg.go:
go/src/cmd/go/internal/load/pkg.go
Line 2271 in e39e965
| if err := module.CheckFilePath(name); err != nil { |
Where module.CheckFilePath checks for a number of restrictions on the given name:
| func CheckFilePath(path string) error { |
The commit (930c2c9) that introduced the usage of module.CheckFilePath references CL https://go-review.googlesource.com/c/go/+/290709, which talks a lot about fs.ValidPath. It seems like module.CheckFilePath was used to avoid certain bad windows filenames (COM, PRN, ...), but module.CheckFilePath is fairly restrictive in that it accepts a restricted set of ascii characters:
| const allowed = "!#$%&()+,-.=@[]^_{}~ " |
This proposal could be resolved by adding single quote ' to that allowed variable, although that would impact other code that uses the golang.org/x/mod/module module. Perhaps a solution would be a combination of fs.ValidPath and something that checks the bad windows names?
func isBadEmbedName(name string) bool {
if !fs.ValidName(name) {
return true
}
if module.IsBadWindowsName(name) {
return true
}
...
}