Fix: letter case should be ignored while validating file extension

pull/247/head
HFO4 5 years ago
parent 3741da692b
commit 5aa61301af

@ -4,6 +4,7 @@ import (
"context"
"github.com/HFO4/cloudreve/pkg/util"
"path/filepath"
"strings"
)
// ValidateFileSize 验证上传的文件大小是否超出限制
@ -26,7 +27,7 @@ func (fs *FileSystem) ValidateExtension(ctx context.Context, fileName string) bo
return true
}
ext := filepath.Ext(fileName)
ext := strings.ToLower(filepath.Ext(fileName))
// 无扩展名时
if len(ext) == 0 {
return false

@ -86,5 +86,6 @@ func TestFileSystem_ValidateExtension(t *testing.T) {
asserts.False(fs.ValidateExtension(ctx, "1.jpg.png"))
asserts.True(fs.ValidateExtension(ctx, "1.txt"))
asserts.True(fs.ValidateExtension(ctx, "1.png.jpg"))
asserts.True(fs.ValidateExtension(ctx, "1.png.jpG"))
asserts.False(fs.ValidateExtension(ctx, "1.png"))
}

Loading…
Cancel
Save