Skip to content

Commit b54cd94

Browse files
author
Jay Conrod
committed
embed, io/fs: clarify that leading and trailing slashes are disallowed
Fixes #44012 Change-Id: I5782cea301a65ae12ba870ff1e6b2e0a2651dc09 Reviewed-on: https://go-review.googlesource.com/c/go/+/290071 Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Jay Conrod <[email protected]>
1 parent 4516afe commit b54cd94

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/embed/embed.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@
6161
// The Go build system will recognize the directives and arrange for the declared variable
6262
// (in the example above, content) to be populated with the matching files from the file system.
6363
//
64-
// The //go:embed directive accepts multiple space-separated patterns for brevity,
65-
// but it can also be repeated, to avoid very long lines when there are many patterns.
66-
// The patterns are interpreted relative to the package directory containing the source file.
67-
// The path separator is a forward slash, even on Windows systems.
68-
// To allow for naming files with spaces in their names, patterns can be written
69-
// as Go double-quoted or back-quoted string literals.
64+
// The //go:embed directive accepts multiple space-separated patterns for
65+
// brevity, but it can also be repeated, to avoid very long lines when there are
66+
// many patterns. The patterns are interpreted relative to the package directory
67+
// containing the source file. The path separator is a forward slash, even on
68+
// Windows systems. Patterns may not contain ‘.’ or ‘..’ or empty path elements,
69+
// nor may they begin or end with a slash. To match everything in the current
70+
// directory, use ‘*’ instead of ‘.’. To allow for naming files with spaces in
71+
// their names, patterns can be written as Go double-quoted or back-quoted
72+
// string literals.
7073
//
7174
// If a pattern names a directory, all files in the subtree rooted at that directory are
7275
// embedded (recursively), except that files with names beginning with ‘.’ or ‘_’
@@ -87,9 +90,6 @@
8790
// Matches for empty directories are ignored. After that, each pattern in a //go:embed line
8891
// must match at least one file or non-empty directory.
8992
//
90-
// Patterns must not contain ‘.’ or ‘..’ path elements nor begin with a leading slash.
91-
// To match everything in the current directory, use ‘*’ instead of ‘.’.
92-
//
9393
// If any patterns are invalid or have invalid matches, the build will fail.
9494
//
9595
// Strings and Bytes

src/io/fs/fs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type FS interface {
3636
// sequences of path elements, like “x/y/z”.
3737
// Path names must not contain a “.” or “..” or empty element,
3838
// except for the special case that the root directory is named “.”.
39+
// Leading and trailing slashes (like “/x” or “x/”) are not allowed.
3940
//
4041
// Paths are slash-separated on all systems, even Windows.
4142
// Backslashes must not appear in path names.

0 commit comments

Comments
 (0)