fix: strip nested BasePathFs base segment from BasePathFile.Name
BasePathFile.Name trimmed only filepath.Clean(path) from the wrapped
file name. filepath.Clean drops the trailing separator, and a nested
BasePathFile reports a name whose base segment is preceded by a leading
separator (for example "/123/x"), which the cleaned base ("123") does
not match. The base then leaked into Name and callers double-prepended
it. Trim the separator-prefixed form too so nested BasePathFs report a
name that round-trips.
Fixes #428
This commit is contained in:
1 parent
9f78513f63
commit
b778e8e78b
2 files changed
+38
-1
No files matched your search
+10
-1
@@ -37,7 +37,16 @@ type BasePathFile struct {
|
||||
|
||||
func (f *BasePathFile) Name() string {
|
||||
sourcename := f.File.Name()
|
||||
return strings.TrimPrefix(sourcename, filepath.Clean(f.path))
|
||||
base := filepath.Clean(f.path)
|
||||
name := strings.TrimPrefix(sourcename, base)
|
||||
if name == sourcename {
|
||||
// filepath.Clean drops the leading separator from the base path, so a
|
||||
// name produced by a wrapped (nested) BasePathFile can still carry the
|
||||
// base preceded by a separator. Strip that form as well, otherwise the
|
||||
// base segment leaks into the reported name.
|
||||
name = strings.TrimPrefix(sourcename, string(filepath.Separator)+base)
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error) {
|
||||
|
||||
Reference in new issue
Block a user