jottacloud: fix invalid url in output from link command

Fixes #5370
This commit is contained in:
albertony 2021-05-31 09:31:35 +02:00
parent df60e6323c
commit 41f561bf26

View File

@ -350,10 +350,21 @@ func (f *Fs) Features() *fs.Features {
return f.features return f.features
} }
// parsePath parses a box 'url' // joinPath joins two path/url elements
func parsePath(path string) (root string) { //
root = strings.Trim(path, "/") // Does not perform clean on the result like path.Join does,
return // which breaks urls by changing prefix "https://" into "https:/".
func joinPath(base string, rel string) string {
if rel == "" {
return base
}
if strings.HasSuffix(base, "/") {
return base + strings.TrimPrefix(rel, "/")
}
if strings.HasPrefix(rel, "/") {
return strings.TrimSuffix(base, "/") + rel
}
return base + "/" + rel
} }
// retryErrorCodes is a slice of error codes that we will retry // retryErrorCodes is a slice of error codes that we will retry
@ -721,7 +732,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
} }
rootIsDir := strings.HasSuffix(root, "/") rootIsDir := strings.HasSuffix(root, "/")
root = parsePath(root) root = strings.Trim(root, "/")
f := &Fs{ f := &Fs{
name: name, name: name,
@ -1259,8 +1270,7 @@ func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration,
if result.PublicSharePath == "" { if result.PublicSharePath == "" {
return "", errors.New("couldn't create public link - no link path received") return "", errors.New("couldn't create public link - no link path received")
} }
link = path.Join(baseURL, result.PublicSharePath) return joinPath(baseURL, result.PublicSharePath), nil
return link, nil
} }
// About gets quota information // About gets quota information