Skip to content

Commit

Permalink
Fix checkName for FileFS on Windows
Browse files Browse the repository at this point in the history
Using path.Base() doesn't parse correctly for WIndows filepaths.
Use filepath.Base() instead.
  • Loading branch information
mholt committed Sep 1, 2023
1 parent e2261a1 commit 9f827e1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs.go
Expand Up @@ -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
Expand Down

0 comments on commit 9f827e1

Please sign in to comment.