Skip to content

Commit 003d9a0

Browse files
committed
drop filepath.Clean for useless
1 parent cc7b591 commit 003d9a0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

modules/storage/local.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +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-
prefix_trim := filepath.Clean(prefix)
134-
dir = filepath.Join(l.dir, prefix_trim)
133+
dir = filepath.Join(l.dir, prefix)
135134
if !strings.HasPrefix(dir, strings.TrimSuffix(l.dir, "/")) {
136135
return ErrIllegalPath
137136
}

modules/storage/local_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ func TestLocalStorageIterator(t *testing.T) {
7171
}
7272

7373
expected_list := map[string][]string{
74-
"a": {"a/1.txt"},
75-
"b": {"b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"},
76-
"": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"},
77-
"/": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"},
78-
"/../../../tmp": {}, // empty dir
74+
"a": {"a/1.txt"},
75+
"b": {"b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"},
76+
"": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"},
77+
"/": {"a/1.txt", "b/1.txt", "b/2.txt", "b/3.txt", "b/x 4.txt"},
78+
"a/b/../../a": {"a/1.txt"},
7979
}
8080
for dir, expected := range expected_list {
8181
count := 0
@@ -93,6 +93,7 @@ func TestLocalStorageIterator(t *testing.T) {
9393
illegal_dirs := []string{
9494
"../a",
9595
"../../etc/hosts",
96+
"../a/../b",
9697
}
9798
for _, dir := range illegal_dirs {
9899
err = l.IterateObjects(dir, func(path string, f Object) error {

0 commit comments

Comments
 (0)