mirror of
				https://github.com/cloudreve/cloudreve.git
				synced 2025-10-31 16:49:03 +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 获取文件的绝对路径 | // GetSourcePath 获取文件的绝对路径 | ||||||
| func (info *FileInfo) GetSourcePath() string { | func (info *FileInfo) GetSourcePath() string { | ||||||
| 	res, err := url.PathUnescape( | 	return strings.TrimPrefix( | ||||||
| 		strings.TrimPrefix( | 		path.Join( | ||||||
| 			path.Join( | 			strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"), | ||||||
| 				strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"), | 			info.Name, | ||||||
| 				info.Name, |  | ||||||
| 			), |  | ||||||
| 			"/", |  | ||||||
| 		), | 		), | ||||||
|  | 		"/", | ||||||
| 	) | 	) | ||||||
| 	if err != nil { |  | ||||||
| 		return "" |  | ||||||
| 	} |  | ||||||
| 	return res |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Error 实现error接口 | // Error 实现error接口 | ||||||
|  | |||||||
| @ -138,28 +138,13 @@ 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{ | ||||||
| 	// 成功 | 		Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg", | ||||||
| 	{ | 		ParentReference: parentReference{ | ||||||
| 		fileInfo := FileInfo{ | 			Path: "/drive/root:/123/321", | ||||||
| 			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()) |  | ||||||
| 	} | 	} | ||||||
|  | 	asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestClient_GetRequestURL(t *testing.T) { | func TestClient_GetRequestURL(t *testing.T) { | ||||||
|  | |||||||
| @ -239,7 +239,7 @@ func (service *S3Callback) PreProcess(c *gin.Context) serializer.Response { | |||||||
| 	return ProcessCallback(service, c) | 	return ProcessCallback(service, c) | ||||||
| } | } | ||||||
|  |  | ||||||
| // PreProcess 对OneDrive客户端回调进行预处理验证 | // PreProcess 对从机客户端回调进行预处理验证 | ||||||
| func (service *UploadCallbackService) PreProcess(c *gin.Context) serializer.Response { | func (service *UploadCallbackService) PreProcess(c *gin.Context) serializer.Response { | ||||||
| 	// 创建文件系统 | 	// 创建文件系统 | ||||||
| 	fs, err := filesystem.NewFileSystemFromCallback(c) | 	fs, err := filesystem.NewFileSystemFromCallback(c) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 HFO4
					HFO4