rest: rename URLEscape to URLPathEscape for consistency with go1.8

This commit is contained in:
Nick Craig-Wood 2018-01-05 15:55:43 +00:00
parent ef89f1f1a7
commit be4ed14525
7 changed files with 15 additions and 15 deletions

View File

@ -89,7 +89,7 @@ func NewFs(name, root string) (fs.Fs, error) {
if err != nil {
return nil, err
}
u, err := rest.URLJoin(base, rest.URLEscape(root))
u, err := rest.URLJoin(base, rest.URLPathEscape(root))
if err != nil {
return nil, err
}
@ -186,7 +186,7 @@ func (f *Fs) NewObject(remote string) (fs.Object, error) {
// Join's the remote onto the base URL
func (f *Fs) url(remote string) string {
return f.endpointURL + rest.URLEscape(remote)
return f.endpointURL + rest.URLPathEscape(remote)
}
func parseInt64(s string) int64 {

View File

@ -223,7 +223,7 @@ func TestParseName(t *testing.T) {
{"http://example.com/dir/", "subdir/potato", false, ""},
{"http://example.com/dir/", "With percent %25.txt", true, "With percent %.txt"},
{"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)
require.NoError(t, err)

View File

@ -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) {
opts := rest.Opts{
Method: "GET",
Path: "/root:/" + rest.URLEscape(replaceReservedChars(path)),
Path: "/root:/" + rest.URLPathEscape(replaceReservedChars(path)),
}
err = f.pacer.Call(func() (bool, error) {
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) {
opts := rest.Opts{
Method: "PATCH",
Path: "/root:/" + rest.URLEscape(o.srvPath()),
Path: "/root:/" + rest.URLPathEscape(o.srvPath()),
}
update := api.SetFileSystemInfo{
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) {
opts := rest.Opts{
Method: "POST",
Path: "/root:/" + rest.URLEscape(o.srvPath()) + ":/upload.createSession",
Path: "/root:/" + rest.URLPathEscape(o.srvPath()) + ":/upload.createSession",
}
var resp *http.Response
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
opts := rest.Opts{
Method: "PUT",
Path: "/root:/" + rest.URLEscape(o.srvPath()) + ":/content",
Path: "/root:/" + rest.URLPathEscape(o.srvPath()) + ":/content",
ContentLength: &size,
Body: in,
}

View File

@ -17,10 +17,10 @@ func URLJoin(base *url.URL, path string) (*url.URL, error) {
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
func URLEscape(in string) string {
func URLPathEscape(in string) string {
var u url.URL
u.Path = in
return u.String()

View File

@ -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/", "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/", 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)
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 {
path string
want string
@ -57,7 +57,7 @@ func TestURLEscape(t *testing.T) {
{"With Colon:", "./With%20Colon:"},
{"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))
}
}

View File

@ -786,7 +786,7 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
}
srcFs := srcObj.fs
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{
Bucket: &f.bucket,
Key: &key,
@ -935,7 +935,7 @@ func (o *Object) SetModTime(modTime time.Time) error {
ACL: &o.fs.acl,
Key: &key,
ContentType: &mimeType,
CopySource: aws.String(rest.URLEscape(sourceKey)),
CopySource: aws.String(rest.URLPathEscape(sourceKey)),
Metadata: o.meta,
MetadataDirective: &directive,
}

View File

@ -232,7 +232,7 @@ func addSlash(s string) string {
// filePath returns a file path (f.root, file)
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)