Skip to content

Commit 97434c7

Browse files
rodcoffanijessegeens
authored andcommitted
fix: handling special characters (#5451)
* fix: propfind for folders with special characters * fix: encode url for eoshttp
1 parent 52e1e25 commit 97434c7

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: Handle special characters in file names correctly
2+
3+
- Fixed PROPFIND response when listing a folder named with special charactrers
4+
5+
https://github.com/cs3org/reva/pull/5451

internal/http/services/owncloud/ocdav/propfind.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ import (
4141
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
4242
"github.com/cs3org/reva/v3/internal/grpc/services/storageprovider"
4343
"github.com/cs3org/reva/v3/pkg/appctx"
44-
"github.com/cs3org/reva/v3/pkg/spaces"
4544
"github.com/cs3org/reva/v3/pkg/permissions"
45+
"github.com/cs3org/reva/v3/pkg/spaces"
4646

4747
"github.com/pkg/errors"
48-
4948

5049
"github.com/cs3org/reva/v3/pkg/publicshare"
5150
"github.com/cs3org/reva/v3/pkg/share"
@@ -512,23 +511,23 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
512511

513512
var href string
514513
if parent != nil {
515-
relativePath, err := filepath.Rel(parent.Path, md.Path)
514+
relativePath, err := filepath.Rel(encodePath(parent.Path), encodePath(md.Path))
516515
if err != nil {
517516
return nil, errors.Wrapf(err, "failed to calculate path relative to parent: %v", md.Path)
518517
}
519-
href, err = url.JoinPath(hrefBase, relativePath)
518+
href, err = url.JoinPath(encodePath(hrefBase), relativePath)
520519
if err != nil {
521520
return nil, errors.Wrapf(err, "failed to join relative path with ref: %v", md.Path)
522521
}
523522
} else {
524523
// If no parent specified, we just take space id + path relative to space
525524
spaceID := md.Id.SpaceId
526525
spacePath, _ := spaces.DecodeSpaceID(spaceID)
527-
relativePath, err := filepath.Rel(spacePath, md.Path)
526+
relativePath, err := filepath.Rel(spacePath, encodePath(md.Path))
528527
if err != nil {
529528
return nil, errors.Wrapf(err, "failed to calculate path relative to space: %v. %v", spacePath, md.Path)
530529
}
531-
href, err = url.JoinPath(hrefBase, spaceID, relativePath)
530+
href, err = url.JoinPath(encodePath(hrefBase), spaceID, relativePath)
532531
if err != nil {
533532
return nil, errors.Wrapf(err, "failed to join relative path with ref: %v", md.Path)
534533
}

pkg/eosclient/eosgrpc/eoshttp.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ type HTTPOptions struct {
6565

6666
// TTL for an idle conn per transport
6767
IdleConnTimeout int
68-
6968
// If the URL is https, then we need to configure this client
7069
// with the usual TLS stuff
7170
// Defaults are /etc/grid-security/hostcert.pem and /etc/grid-security/hostkey.pem
@@ -229,9 +228,11 @@ func (c *EOSHTTPClient) buildFullURL(urlpath string, auth eosclient.Authorizatio
229228
}
230229
}
231230

231+
urlpathEncoded := strings.ReplaceAll(url.PathEscape(urlpath), "%2F", "/")
232+
232233
fullurl := strings.TrimRight(c.opt.BaseURL, "/")
233234
fullurl += "/"
234-
fullurl += strings.TrimLeft(urlpath, "/")
235+
fullurl += strings.TrimLeft(urlpathEncoded, "/")
235236

236237
if pos < 0 {
237238
fullurl += "?"
@@ -243,7 +244,7 @@ func (c *EOSHTTPClient) buildFullURL(urlpath string, auth eosclient.Authorizatio
243244

244245
u, err := url.Parse(fullurl)
245246
if err != nil {
246-
return "", errtypes.PermissionDenied("Could not parse url " + urlpath)
247+
return "", errtypes.PermissionDenied("Could not parse url " + urlpathEncoded)
247248
}
248249

249250
final := strings.ReplaceAll(u.String(), "#", "%23")
@@ -379,11 +380,11 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
379380
log.Info().Str("func", "PUTFile").Str("remoteuser", remoteuser).Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", urlpath).Int64("length", length).Str("app", app).Msg("")
380381

381382
// Now send the req and see what happens
382-
tempUrl, err := c.buildFullURL(urlpath, auth)
383+
tempURL, err := c.buildFullURL(urlpath, auth)
383384
if err != nil {
384385
return err
385386
}
386-
base, err := url.Parse(tempUrl)
387+
base, err := url.Parse(tempURL)
387388
if err != nil {
388389
return errtypes.PermissionDenied("Could not parse url " + urlpath)
389390
}

0 commit comments

Comments
 (0)