提交 5af3c4e2 编写于 作者: H HFO4

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

上级 4c458df6
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册