fix: metadata mismatch if file name contains %
while uploading to OneDrive/SharePoint
This commit is contained in:
parent
6b0b44f6d0
commit
560097145b
2 changed files with 27 additions and 7 deletions
|
@ -37,9 +37,14 @@ const (
|
|||
|
||||
// GetSourcePath 获取文件的绝对路径
|
||||
func (info *FileInfo) GetSourcePath() string {
|
||||
res, err := url.PathUnescape(info.ParentReference.Path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimPrefix(
|
||||
path.Join(
|
||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
||||
strings.TrimPrefix(res, "/drive/root:"),
|
||||
info.Name,
|
||||
),
|
||||
"/",
|
||||
|
|
|
@ -138,13 +138,28 @@ func TestRequest(t *testing.T) {
|
|||
|
||||
func TestFileInfo_GetSourcePath(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
fileInfo := FileInfo{
|
||||
Name: "文件名.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
|
||||
// 成功
|
||||
{
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/32%201",
|
||||
},
|
||||
}
|
||||
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())
|
||||
}
|
||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
||||
}
|
||||
|
||||
func TestClient_GetRequestURL(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue