mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
fix: metadata mismatch if file name contains % while uploading to OneDrive/SharePoint (#1301)
This commit is contained in:
@@ -37,19 +37,13 @@ const (
|
||||
|
||||
// GetSourcePath 获取文件的绝对路径
|
||||
func (info *FileInfo) GetSourcePath() string {
|
||||
res, err := url.PathUnescape(
|
||||
strings.TrimPrefix(
|
||||
path.Join(
|
||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
||||
info.Name,
|
||||
),
|
||||
"/",
|
||||
return strings.TrimPrefix(
|
||||
path.Join(
|
||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
||||
info.Name,
|
||||
),
|
||||
"/",
|
||||
)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Error 实现error接口
|
||||
|
||||
@@ -138,28 +138,13 @@ func TestRequest(t *testing.T) {
|
||||
|
||||
func TestFileInfo_GetSourcePath(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
// 成功
|
||||
{
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
}
|
||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
||||
}
|
||||
|
||||
// 失败
|
||||
{
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8g.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
}
|
||||
asserts.Equal("", fileInfo.GetSourcePath())
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
}
|
||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
||||
}
|
||||
|
||||
func TestClient_GetRequestURL(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user