Fix: directory renaming should not be limited by file extensions (#395)
This commit is contained in:
parent
4c458df666
commit
5af3c4e244
3 changed files with 31 additions and 2 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -48,6 +48,8 @@ jobs:
|
|||
with:
|
||||
clean: false
|
||||
submodules: 'recursive'
|
||||
- run: |
|
||||
git fetch --prune --unshallow --tags
|
||||
|
||||
- name: Get dependencies and build
|
||||
run: |
|
||||
|
|
|
@ -32,7 +32,7 @@ type Object struct {
|
|||
// Rename 重命名对象
|
||||
func (fs *FileSystem) Rename(ctx context.Context, dir, file []uint, new string) (err error) {
|
||||
// 验证新名字
|
||||
if !fs.ValidateLegalName(ctx, new) || !fs.ValidateExtension(ctx, new) {
|
||||
if !fs.ValidateLegalName(ctx, new) || (len(file) > 0 && !fs.ValidateExtension(ctx, new)) {
|
||||
return ErrIllegalObjectName
|
||||
}
|
||||
|
||||
|
|
|
@ -707,12 +707,39 @@ func TestFileSystem_Rename(t *testing.T) {
|
|||
asserts.Equal(ErrPathNotExist, err)
|
||||
}
|
||||
|
||||
// 新名字不合法
|
||||
// 新名字是目录,不合法
|
||||
{
|
||||
err := fs.Rename(ctx, []uint{10}, []uint{}, "ne/w")
|
||||
asserts.Error(err)
|
||||
asserts.Equal(ErrIllegalObjectName, err)
|
||||
}
|
||||
|
||||
// 新名字是文件,不合法
|
||||
{
|
||||
err := fs.Rename(ctx, []uint{}, []uint{10}, "ne/w")
|
||||
asserts.Error(err)
|
||||
asserts.Equal(ErrIllegalObjectName, err)
|
||||
}
|
||||
|
||||
// 新名字是文件,扩展名不合法
|
||||
{
|
||||
fs.User.Policy.OptionsSerialized.FileType = []string{"txt"}
|
||||
err := fs.Rename(ctx, []uint{}, []uint{10}, "1.jpg")
|
||||
asserts.Error(err)
|
||||
asserts.Equal(ErrIllegalObjectName, err)
|
||||
}
|
||||
|
||||
// 新名字是目录,不应该检测扩展名
|
||||
{
|
||||
fs.User.Policy.OptionsSerialized.FileType = []string{"txt"}
|
||||
mock.ExpectQuery("SELECT(.+)folders(.+)").
|
||||
WithArgs(10, 1).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}))
|
||||
err := fs.Rename(ctx, []uint{10}, []uint{}, "new")
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.Error(err)
|
||||
asserts.Equal(ErrPathNotExist, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystem_SaveTo(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue