commit 4c257bcb464710f7f45c0b38661bfff7e2941420
parent e40c9a2d59a1d779c89d5cf7e337d7fb10009199
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 7 Jan 2024 13:51:56 +0900
export cleanPath
Diffstat:
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/client/fs.go b/client/fs.go
@@ -48,7 +48,7 @@ func (fsys *FS) OpenFile(name string, omode lib9p.OpenMode) (lib9p.File, error)
// CleanPath cleans name.
// It first call path.Clean(name) and then
// delete trailing ".." elements.
-func cleanPath(name string) string {
+func CleanPath(name string) string {
name = path.Clean(name)
for strings.HasPrefix(name, "../") {
name = name[3:]
@@ -71,7 +71,7 @@ func (fsys *FS) walkFile(name string) (*File, error) {
}
var wname []string
if name != "." {
- wname = strings.Split(cleanPath(name), "/")
+ wname = strings.Split(CleanPath(name), "/")
}
tag, err := fsys.tPool.add()
if err != nil {
diff --git a/client/fs2_test.go b/client/fs2_test.go
@@ -25,9 +25,9 @@ func TestCleanPath(t *testing.T) {
{"../a/../b/../c/../d/", "d"},
}
for _, test := range tests {
- got := cleanPath(test.name)
+ got := CleanPath(test.name)
if got != test.want {
- t.Errorf("cleanPath(%q) = %q, want: %q", test.name, got, test.want)
+ t.Errorf("CleanPath(%q) = %q, want: %q", test.name, got, test.want)
}
}
}