mirror of https://github.com/cloudreve/Cloudreve
Fix: letter case should be ignored while validating file extension
parent
3741da692b
commit
5aa61301af
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/HFO4/cloudreve/pkg/util"
|
"github.com/HFO4/cloudreve/pkg/util"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidateFileSize 验证上传的文件大小是否超出限制
|
// ValidateFileSize 验证上传的文件大小是否超出限制
|
||||||
|
@ -26,7 +27,7 @@ func (fs *FileSystem) ValidateExtension(ctx context.Context, fileName string) bo
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
ext := filepath.Ext(fileName)
|
ext := strings.ToLower(filepath.Ext(fileName))
|
||||||
// 无扩展名时
|
// 无扩展名时
|
||||||
if len(ext) == 0 {
|
if len(ext) == 0 {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -86,5 +86,6 @@ func TestFileSystem_ValidateExtension(t *testing.T) {
|
||||||
asserts.False(fs.ValidateExtension(ctx, "1.jpg.png"))
|
asserts.False(fs.ValidateExtension(ctx, "1.jpg.png"))
|
||||||
asserts.True(fs.ValidateExtension(ctx, "1.txt"))
|
asserts.True(fs.ValidateExtension(ctx, "1.txt"))
|
||||||
asserts.True(fs.ValidateExtension(ctx, "1.png.jpg"))
|
asserts.True(fs.ValidateExtension(ctx, "1.png.jpg"))
|
||||||
|
asserts.True(fs.ValidateExtension(ctx, "1.png.jpG"))
|
||||||
asserts.False(fs.ValidateExtension(ctx, "1.png"))
|
asserts.False(fs.ValidateExtension(ctx, "1.png"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue