mirror of https://github.com/cloudreve/Cloudreve
fix: metadata mismatch if file name contains `%` while uploading to OneDrive/SharePoint
parent
6b0b44f6d0
commit
560097145b
|
@ -37,9 +37,14 @@ const (
|
||||||
|
|
||||||
// GetSourcePath 获取文件的绝对路径
|
// GetSourcePath 获取文件的绝对路径
|
||||||
func (info *FileInfo) GetSourcePath() string {
|
func (info *FileInfo) GetSourcePath() string {
|
||||||
|
res, err := url.PathUnescape(info.ParentReference.Path)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
return strings.TrimPrefix(
|
return strings.TrimPrefix(
|
||||||
path.Join(
|
path.Join(
|
||||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
strings.TrimPrefix(res, "/drive/root:"),
|
||||||
info.Name,
|
info.Name,
|
||||||
),
|
),
|
||||||
"/",
|
"/",
|
||||||
|
|
|
@ -138,13 +138,28 @@ func TestRequest(t *testing.T) {
|
||||||
|
|
||||||
func TestFileInfo_GetSourcePath(t *testing.T) {
|
func TestFileInfo_GetSourcePath(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
|
|
||||||
|
// 成功
|
||||||
|
{
|
||||||
fileInfo := FileInfo{
|
fileInfo := FileInfo{
|
||||||
Name: "文件名.jpg",
|
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||||
ParentReference: parentReference{
|
ParentReference: parentReference{
|
||||||
Path: "/drive/root:/123/321",
|
Path: "/drive/root:/123/32%201",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
asserts.Equal("123/32 1/%e6%96%87%e4%bb%b6%e5%90%8d.jpg", fileInfo.GetSourcePath())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 失败
|
||||||
|
{
|
||||||
|
fileInfo := FileInfo{
|
||||||
|
Name: "123.jpg",
|
||||||
|
ParentReference: parentReference{
|
||||||
|
Path: "/drive/root:/123/%e6%96%87%e4%bb%b6%e5%90%8g",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
asserts.Equal("", fileInfo.GetSourcePath())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_GetRequestURL(t *testing.T) {
|
func TestClient_GetRequestURL(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue