mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Fix: able to upload empty file
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestFileSystem_AddFile(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
file := local.FileData{
|
||||
file := local.FileStream{
|
||||
Size: 5,
|
||||
Name: "1.txt",
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func TestGenericBeforeUpload(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
file := local.FileData{
|
||||
file := local.FileStream{
|
||||
Size: 5,
|
||||
Name: "1.txt",
|
||||
}
|
||||
|
||||
@@ -28,12 +28,18 @@ func (fs *FileSystem) ValidateLegalName(ctx context.Context, name string) bool {
|
||||
if len(name) >= 256 {
|
||||
return false
|
||||
}
|
||||
|
||||
// 是否为空限制
|
||||
if len(name) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidateFileSize 验证上传的文件大小是否超出限制
|
||||
func (fs *FileSystem) ValidateFileSize(ctx context.Context, size uint64) bool {
|
||||
return size <= fs.User.Policy.MaxSize
|
||||
return size <= fs.User.Policy.MaxSize && size != 0
|
||||
}
|
||||
|
||||
// ValidateCapacity 验证并扣除用户容量
|
||||
|
||||
@@ -36,6 +36,7 @@ func TestFileSystem_ValidateLegalName(t *testing.T) {
|
||||
asserts.False(fs.ValidateLegalName(ctx, "../11.txt"))
|
||||
asserts.False(fs.ValidateLegalName(ctx, "/11.txt"))
|
||||
asserts.False(fs.ValidateLegalName(ctx, "\\11.txt"))
|
||||
asserts.False(fs.ValidateLegalName(ctx, ""))
|
||||
}
|
||||
|
||||
func TestFileSystem_ValidateCapacity(t *testing.T) {
|
||||
@@ -72,6 +73,7 @@ func TestFileSystem_ValidateFileSize(t *testing.T) {
|
||||
asserts.True(fs.ValidateFileSize(ctx, 5))
|
||||
asserts.True(fs.ValidateFileSize(ctx, 10))
|
||||
asserts.False(fs.ValidateFileSize(ctx, 11))
|
||||
asserts.False(fs.ValidateFileSize(ctx, 0))
|
||||
}
|
||||
|
||||
func TestFileSystem_ValidateExtension(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user