mirror of https://github.com/rclone/rclone.git
rest: rename URLEscape to URLPathEscape for consistency with go1.8
This commit is contained in:
parent
ef89f1f1a7
commit
be4ed14525
|
@ -89,7 +89,7 @@ func NewFs(name, root string) (fs.Fs, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
u, err := rest.URLJoin(base, rest.URLEscape(root))
|
u, err := rest.URLJoin(base, rest.URLPathEscape(root))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func (f *Fs) NewObject(remote string) (fs.Object, error) {
|
||||||
|
|
||||||
// Join's the remote onto the base URL
|
// Join's the remote onto the base URL
|
||||||
func (f *Fs) url(remote string) string {
|
func (f *Fs) url(remote string) string {
|
||||||
return f.endpointURL + rest.URLEscape(remote)
|
return f.endpointURL + rest.URLPathEscape(remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInt64(s string) int64 {
|
func parseInt64(s string) int64 {
|
||||||
|
|
|
@ -223,7 +223,7 @@ func TestParseName(t *testing.T) {
|
||||||
{"http://example.com/dir/", "subdir/potato", false, ""},
|
{"http://example.com/dir/", "subdir/potato", false, ""},
|
||||||
{"http://example.com/dir/", "With percent %25.txt", true, "With percent %.txt"},
|
{"http://example.com/dir/", "With percent %25.txt", true, "With percent %.txt"},
|
||||||
{"http://example.com/dir/", "With colon :", false, ""},
|
{"http://example.com/dir/", "With colon :", false, ""},
|
||||||
{"http://example.com/dir/", rest.URLEscape("With colon :"), true, "With colon :"},
|
{"http://example.com/dir/", rest.URLPathEscape("With colon :"), true, "With colon :"},
|
||||||
} {
|
} {
|
||||||
u, err := url.Parse(test.base)
|
u, err := url.Parse(test.base)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -308,7 +308,7 @@ func shouldRetry(resp *http.Response, err error) (bool, error) {
|
||||||
func (f *Fs) readMetaDataForPath(path string) (info *api.Item, resp *http.Response, err error) {
|
func (f *Fs) readMetaDataForPath(path string) (info *api.Item, resp *http.Response, err error) {
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "/root:/" + rest.URLEscape(replaceReservedChars(path)),
|
Path: "/root:/" + rest.URLPathEscape(replaceReservedChars(path)),
|
||||||
}
|
}
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
resp, err = f.srv.CallJSON(&opts, nil, &info)
|
resp, err = f.srv.CallJSON(&opts, nil, &info)
|
||||||
|
@ -1024,7 +1024,7 @@ func (o *Object) ModTime() time.Time {
|
||||||
func (o *Object) setModTime(modTime time.Time) (*api.Item, error) {
|
func (o *Object) setModTime(modTime time.Time) (*api.Item, error) {
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "PATCH",
|
Method: "PATCH",
|
||||||
Path: "/root:/" + rest.URLEscape(o.srvPath()),
|
Path: "/root:/" + rest.URLPathEscape(o.srvPath()),
|
||||||
}
|
}
|
||||||
update := api.SetFileSystemInfo{
|
update := api.SetFileSystemInfo{
|
||||||
FileSystemInfo: api.FileSystemInfoFacet{
|
FileSystemInfo: api.FileSystemInfoFacet{
|
||||||
|
@ -1079,7 +1079,7 @@ func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
||||||
func (o *Object) createUploadSession() (response *api.CreateUploadResponse, err error) {
|
func (o *Object) createUploadSession() (response *api.CreateUploadResponse, err error) {
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Path: "/root:/" + rest.URLEscape(o.srvPath()) + ":/upload.createSession",
|
Path: "/root:/" + rest.URLPathEscape(o.srvPath()) + ":/upload.createSession",
|
||||||
}
|
}
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
|
@ -1185,7 +1185,7 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "PUT",
|
Method: "PUT",
|
||||||
Path: "/root:/" + rest.URLEscape(o.srvPath()) + ":/content",
|
Path: "/root:/" + rest.URLPathEscape(o.srvPath()) + ":/content",
|
||||||
ContentLength: &size,
|
ContentLength: &size,
|
||||||
Body: in,
|
Body: in,
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@ func URLJoin(base *url.URL, path string) (*url.URL, error) {
|
||||||
return base.ResolveReference(rel), nil
|
return base.ResolveReference(rel), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// URLEscape escapes URL path the in string using URL escaping rules
|
// URLPathEscape escapes URL path the in string using URL escaping rules
|
||||||
//
|
//
|
||||||
// This mimics url.PathEscape which only available from go 1.8
|
// This mimics url.PathEscape which only available from go 1.8
|
||||||
func URLEscape(in string) string {
|
func URLPathEscape(in string) string {
|
||||||
var u url.URL
|
var u url.URL
|
||||||
u.Path = in
|
u.Path = in
|
||||||
return u.String()
|
return u.String()
|
||||||
|
|
|
@ -30,7 +30,7 @@ func TestURLJoin(t *testing.T) {
|
||||||
{"http://example.com/dir/", "subdir/potato", true, "http://example.com/dir/subdir/potato"},
|
{"http://example.com/dir/", "subdir/potato", true, "http://example.com/dir/subdir/potato"},
|
||||||
{"http://example.com/dir/", "With percent %25.txt", true, "http://example.com/dir/With%20percent%20%25.txt"},
|
{"http://example.com/dir/", "With percent %25.txt", true, "http://example.com/dir/With%20percent%20%25.txt"},
|
||||||
{"http://example.com/dir/", "With colon :", false, ""},
|
{"http://example.com/dir/", "With colon :", false, ""},
|
||||||
{"http://example.com/dir/", URLEscape("With colon :"), true, "http://example.com/dir/With%20colon%20:"},
|
{"http://example.com/dir/", URLPathEscape("With colon :"), true, "http://example.com/dir/With%20colon%20:"},
|
||||||
} {
|
} {
|
||||||
u, err := url.Parse(test.base)
|
u, err := url.Parse(test.base)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -46,7 +46,7 @@ func TestURLJoin(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestURLEscape(t *testing.T) {
|
func TestURLPathEscape(t *testing.T) {
|
||||||
for i, test := range []struct {
|
for i, test := range []struct {
|
||||||
path string
|
path string
|
||||||
want string
|
want string
|
||||||
|
@ -57,7 +57,7 @@ func TestURLEscape(t *testing.T) {
|
||||||
{"With Colon:", "./With%20Colon:"},
|
{"With Colon:", "./With%20Colon:"},
|
||||||
{"With Percent%", "With%20Percent%25"},
|
{"With Percent%", "With%20Percent%25"},
|
||||||
} {
|
} {
|
||||||
got := URLEscape(test.path)
|
got := URLPathEscape(test.path)
|
||||||
assert.Equal(t, test.want, got, fmt.Sprintf("Test %d path = %q", i, test.path))
|
assert.Equal(t, test.want, got, fmt.Sprintf("Test %d path = %q", i, test.path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
s3/s3.go
4
s3/s3.go
|
@ -786,7 +786,7 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
|
||||||
}
|
}
|
||||||
srcFs := srcObj.fs
|
srcFs := srcObj.fs
|
||||||
key := f.root + remote
|
key := f.root + remote
|
||||||
source := rest.URLEscape(srcFs.bucket + "/" + srcFs.root + srcObj.remote)
|
source := rest.URLPathEscape(srcFs.bucket + "/" + srcFs.root + srcObj.remote)
|
||||||
req := s3.CopyObjectInput{
|
req := s3.CopyObjectInput{
|
||||||
Bucket: &f.bucket,
|
Bucket: &f.bucket,
|
||||||
Key: &key,
|
Key: &key,
|
||||||
|
@ -935,7 +935,7 @@ func (o *Object) SetModTime(modTime time.Time) error {
|
||||||
ACL: &o.fs.acl,
|
ACL: &o.fs.acl,
|
||||||
Key: &key,
|
Key: &key,
|
||||||
ContentType: &mimeType,
|
ContentType: &mimeType,
|
||||||
CopySource: aws.String(rest.URLEscape(sourceKey)),
|
CopySource: aws.String(rest.URLPathEscape(sourceKey)),
|
||||||
Metadata: o.meta,
|
Metadata: o.meta,
|
||||||
MetadataDirective: &directive,
|
MetadataDirective: &directive,
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ func addSlash(s string) string {
|
||||||
|
|
||||||
// filePath returns a file path (f.root, file)
|
// filePath returns a file path (f.root, file)
|
||||||
func (f *Fs) filePath(file string) string {
|
func (f *Fs) filePath(file string) string {
|
||||||
return rest.URLEscape(path.Join(f.root, file))
|
return rest.URLPathEscape(path.Join(f.root, file))
|
||||||
}
|
}
|
||||||
|
|
||||||
// dirPath returns a directory path (f.root, dir)
|
// dirPath returns a directory path (f.root, dir)
|
||||||
|
|
Loading…
Reference in New Issue