Skip to content

Commit 44c4c82

Browse files
committed
update util.CleanPath usage, drop useless error const
1 parent 1b9ca29 commit 44c4c82

File tree

3 files changed

+1
-21
lines changed

3 files changed

+1
-21
lines changed

modules/storage/local.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ func (l *LocalStorage) URL(path, name string) (*url.URL, error) {
130130
func (l *LocalStorage) IterateObjects(prefix string, fn func(path string, obj Object) error) error {
131131
dir := l.dir
132132
if prefix != "" {
133-
dir = util.CleanPath(filepath.Join(l.dir, prefix))
134-
if !strings.HasPrefix(dir, strings.TrimSuffix(l.dir, "/")) {
135-
return ErrIllegalPath
136-
}
133+
dir = filepath.Join(l.dir, util.CleanPath(prefix))
137134
}
138135
return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
139136
if err != nil {

modules/storage/local_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,4 @@ func TestLocalStorageIterator(t *testing.T) {
9191
assert.NoError(t, err)
9292
assert.Equal(t, count, len(expected))
9393
}
94-
95-
// illegal dir
96-
illegalDirs := []string{
97-
"../a",
98-
"../../etc/hosts",
99-
"../a/../b",
100-
}
101-
for _, dir := range illegalDirs {
102-
err = l.IterateObjects(dir, func(path string, f Object) error {
103-
defer f.Close()
104-
return nil
105-
})
106-
assert.Error(t, err, ErrIllegalPath)
107-
}
10894
}

modules/storage/storage.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import (
1818
// ErrURLNotSupported represents url is not supported
1919
var ErrURLNotSupported = errors.New("url method not supported")
2020

21-
// ErrIllegalPath represents path is illegal
22-
var ErrIllegalPath = errors.New("illegal path")
23-
2421
// ErrInvalidConfiguration is called when there is invalid configuration for a storage
2522
type ErrInvalidConfiguration struct {
2623
cfg interface{}

0 commit comments

Comments
 (0)