From 08d1d4a126a9a03cfd0c44c6334396066f0cbd1e Mon Sep 17 00:00:00 2001 From: DenKoren Date: Mon, 25 Mar 2024 07:48:41 +0100 Subject: [PATCH 1/2] allow absolute paths in BasePathFs when prefix is "" on windows --- basepath.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/basepath.go b/basepath.go index 2e72793a..faa1012a 100644 --- a/basepath.go +++ b/basepath.go @@ -51,7 +51,7 @@ func NewBasePathFs(source Fs, path string) Fs { // on a file outside the base path it returns the given file name and an error, // else the given file with the base path prepended func (b *BasePathFs) RealPath(name string) (path string, err error) { - if err := validateBasePathName(name); err != nil { + if err := validateBasePathName(name, b.path); err != nil { return name, err } @@ -64,7 +64,7 @@ func (b *BasePathFs) RealPath(name string) (path string, err error) { return path, nil } -func validateBasePathName(name string) error { +func validateBasePathName(name string, base string) error { if runtime.GOOS != "windows" { // Not much to do here; // the virtual file paths all look absolute on *nix. @@ -73,7 +73,7 @@ func validateBasePathName(name string) error { // On Windows a common mistake would be to provide an absolute OS path // We could strip out the base part, but that would not be very portable. - if filepath.IsAbs(name) { + if filepath.IsAbs(name) && base != "" { return os.ErrNotExist } From 8292c090380f8bbc5b03524a589fce11ac1a1189 Mon Sep 17 00:00:00 2001 From: DenKoren Date: Mon, 25 Mar 2024 07:58:26 +0100 Subject: [PATCH 2/2] fix: do not clean bpath when it is empty to not root into '.' --- basepath.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/basepath.go b/basepath.go index faa1012a..251c1a04 100644 --- a/basepath.go +++ b/basepath.go @@ -55,7 +55,10 @@ func (b *BasePathFs) RealPath(name string) (path string, err error) { return name, err } - bpath := filepath.Clean(b.path) + bpath := b.path + if bpath != "" { + bpath = filepath.Clean(b.path) + } path = filepath.Clean(filepath.Join(bpath, name)) if !strings.HasPrefix(path, bpath) { return name, os.ErrNotExist