From 79eebf19939d17c1f4fa1b596e6adae672c11883 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 22 Aug 2016 10:58:49 +0100 Subject: [PATCH] onedrive: fix URL escaping in file names - eg uploading files with `+` in them. Fixes #620 Fixes #218 --- onedrive/onedrive.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/onedrive/onedrive.go b/onedrive/onedrive.go index 1942948ac..adc27a6a5 100644 --- a/onedrive/onedrive.go +++ b/onedrive/onedrive.go @@ -8,6 +8,7 @@ import ( "io" "log" "net/http" + "net/url" "regexp" "strings" "time" @@ -145,7 +146,7 @@ func shouldRetry(resp *http.Response, err error) (bool, error) { func (f *Fs) readMetaDataForPath(path string) (info *api.Item, resp *http.Response, err error) { opts := rest.Opts{ Method: "GET", - Path: "/drive/root:/" + replaceReservedChars(path), + Path: "/drive/root:/" + url.QueryEscape(replaceReservedChars(path)), } err = f.pacer.Call(func() (bool, error) { resp, err = f.srv.CallJSON(&opts, nil, &info) @@ -738,7 +739,7 @@ func (o *Object) ModTime() time.Time { func (o *Object) setModTime(modTime time.Time) (*api.Item, error) { opts := rest.Opts{ Method: "PATCH", - Path: "/drive/root:/" + o.srvPath(), + Path: "/drive/root:/" + url.QueryEscape(o.srvPath()), } update := api.SetFileSystemInfo{ FileSystemInfo: api.FileSystemInfoFacet{ @@ -793,7 +794,7 @@ func (o *Object) Open() (in io.ReadCloser, err error) { func (o *Object) createUploadSession() (response *api.CreateUploadResponse, err error) { opts := rest.Opts{ Method: "POST", - Path: "/drive/root:/" + o.srvPath() + ":/upload.createSession", + Path: "/drive/root:/" + url.QueryEscape(o.srvPath()) + ":/upload.createSession", } var resp *http.Response err = o.fs.pacer.Call(func() (bool, error) { @@ -903,7 +904,7 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) (err error) { var resp *http.Response opts := rest.Opts{ Method: "PUT", - Path: "/drive/root:/" + o.srvPath() + ":/content", + Path: "/drive/root:/" + url.QueryEscape(o.srvPath()) + ":/content", Body: in, } err = o.fs.pacer.CallNoRetry(func() (bool, error) {