Fix: directory renaming should not be limited by file extensions (#395)

pull/398/head
HFO4 5 years ago
parent 4c458df666
commit 5af3c4e244

@ -48,6 +48,8 @@ jobs:
with: with:
clean: false clean: false
submodules: 'recursive' submodules: 'recursive'
- run: |
git fetch --prune --unshallow --tags
- name: Get dependencies and build - name: Get dependencies and build
run: | run: |

@ -32,7 +32,7 @@ type Object struct {
// Rename 重命名对象 // Rename 重命名对象
func (fs *FileSystem) Rename(ctx context.Context, dir, file []uint, new string) (err error) { 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 return ErrIllegalObjectName
} }

@ -707,12 +707,39 @@ func TestFileSystem_Rename(t *testing.T) {
asserts.Equal(ErrPathNotExist, err) asserts.Equal(ErrPathNotExist, err)
} }
// 新名字不合法 // 新名字是目录,不合法
{ {
err := fs.Rename(ctx, []uint{10}, []uint{}, "ne/w") err := fs.Rename(ctx, []uint{10}, []uint{}, "ne/w")
asserts.Error(err) asserts.Error(err)
asserts.Equal(ErrIllegalObjectName, 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) { func TestFileSystem_SaveTo(t *testing.T) {

Loading…
Cancel
Save