From 9f827e1976cbf4acde071fee92f4116c2a4fd402 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 1 Sep 2023 09:56:34 -0600 Subject: [PATCH] Fix checkName for FileFS on Windows Using path.Base() doesn't parse correctly for WIndows filepaths. Use filepath.Base() instead. --- fs.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs.go b/fs.go index eee7e607..2aa5737a 100644 --- a/fs.go +++ b/fs.go @@ -192,11 +192,15 @@ func (f FileFS) Stat(name string) (fs.FileInfo, error) { return os.Stat(f.Path) } +// checkName ensures the name is a valid path and also, in the case of +// the FileFS, that it is either ".", the filename originally passed in +// to create the FileFS, or the base of the filename (name without path). +// Other names do not make sense for a FileFS since the FS is only 1 file. func (f FileFS) checkName(name, op string) error { if !fs.ValidPath(name) { return &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid} } - if name != "." && name != path.Base(f.Path) { + if name != "." && name != f.Path && name != filepath.Base(f.Path) { return &fs.PathError{Op: op, Path: name, Err: fs.ErrNotExist} } return nil