Skip to content

Commit c40dab5

Browse files
committed
refactor(serverHandler/upload): check formname==file explicitly
1 parent 575b153 commit c40dab5

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/serverHandler/upload.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,20 @@ func (h *handler) saveUploadFiles(fsPrefix string, createDir, overwriteExists bo
8181
continue
8282
}
8383
filepath := partFilePath[0:filenameIndex]
84-
prefixSlashIndex := strings.IndexByte(filepath, '/')
85-
if prefixSlashIndex > 0 {
86-
fsInfix = filepath[prefixSlashIndex+1:]
84+
if prefixEndIndex := strings.IndexByte(filepath, '/'); prefixEndIndex > 0 {
85+
fsInfix = filepath[prefixEndIndex+1:]
8786
}
88-
} else if formname != file {
87+
} else if formname == file {
88+
// noop
89+
} else {
90+
errs = append(errs, errors.New("upload: unknown mode "+formname))
8991
continue
9092
}
9193

9294
filePrefix := fsPrefix
9395
if len(fsInfix) > 0 {
9496
if !createDir {
95-
errs = append(errs, errors.New("Upload failed: mkdir is not enabled for "+fsPrefix))
97+
errs = append(errs, errors.New("upload: mkdir is not enabled for "+fsPrefix))
9698
continue
9799
}
98100

test/case/011.alias.upload.bash

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ sleep 0.05 # wait server ready
1111
cleanup
1212

1313
content='my/upload/uploaded.tmp'
14-
curl_upload_content 'http://127.0.0.1:3003/my/upload?upload' files "$content" uploaded.tmp
14+
curl_upload_content 'http://127.0.0.1:3003/my/upload?upload' file "$content" uploaded.tmp
1515
uploaded=$(cat "$fs"/uploaded/2/uploaded.tmp)
1616
assert "$uploaded" "$content"
1717

18+
content='my/upload/uploaded2.tmp'
19+
curl_upload_content 'http://127.0.0.1:3003/my/upload?upload' file "$content" 'temp/dir/uploaded2.tmp'
20+
uploaded=$(cat "$fs"/uploaded/2/uploaded2.tmp)
21+
assert "$uploaded" "$content"
22+
1823
cleanup
1924
jobs -p | xargs kill

0 commit comments

Comments
 (0)