Skip to content

proposal: embed: * pattern should support filenames with single quote #70852

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
kazzmir opened this issue Dec 15, 2024 · 2 comments
Closed

proposal: embed: * pattern should support filenames with single quote #70852

kazzmir opened this issue Dec 15, 2024 · 2 comments
Labels
Milestone

Comments

@kazzmir
Copy link

kazzmir commented Dec 15, 2024

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:

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
  }
  ...
}
@gopherbot gopherbot added this to the Proposal milestone Dec 15, 2024
@seankhliao
Copy link
Member

embed can't do anything until #67562 is resolved.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants