Open dwrz opened 2 years ago
Technically the restriction is implied by
Patterns must not match files outside the package's module
and if you try to download a module with a file containing colons it says
create zip: hello:world: malformed file path "hello:world": invalid char ':'
but it could be clearer.
cc @bcmills @matloob
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to use
embed.FS
to store photographs for a website. There are photographs with a colon in the filename (an RFC3339 formatted timestamp) which were not appearing on the site. The logs reported the following error:On investigation, it appears that files with a colon in the filename are not included in an
embed.FS
. It appears that an error is generated at compilation if a filename with a colon exists in the embedded root directory, but not if the problematic filename is in a subdirectory. In the latter case, the file is simply not included in the embedded FS.This came as a surprise to me, since (1) the limitation with colons is not listed in the
embed
package documentation, (2) fs.ValidPath is documented as follows:To replicate, I set up a directory like the following:
snippet.go
contains the following:When compiled, this returns the following compilation error:
However, if the filename with colons is removed from the top level, the program compiles. It then outputs the following:
subdir/2022-07-22T15:02:45Z.txt
is excluded, and no compilation error is reported.What did you expect to see?
embed.FS
.What did you see instead?
embed.FS
. This left me with the expectation that my files were included in theembed.FS
, when in fact they were not.