Skip to content

S3 path resolution extra slash when joined to bucket with key #167

@theogaraj

Description

@theogaraj

Which operating system and Python version are you using?
Windows 11, Python 3.9.6

Which version of this project are you using?
0.1.4

What did you do?

  1. Created a UPath from an S3 URI of a bucket with key suffix and trailing slash
  2. Used the / operator to create a new S3 path by joining a string to the original UPath
>>> bucket_with_key = UPath('s3://mybucket/withkey/')   # created UPath consisting of bucket and key with trailing slash
>>> subpath_new = bucket_with_key / 'subfolder/myfile.txt'
>>> subpath_new
S3Path('s3://mybucket/withkey//subfolder/myfile.txt')

What did you expect to see?
I would expect to see a single slash between s3://mybucket/withkey and subfolder/myfile.txt

What did you see instead?
Resultant S3Path has a double slash: S3Path('s3://mybucket/withkey//subfolder/myfile.txt')

Additional info
This works as expected when I have just a bucket, or if I have bucket and key without a trailing slash
Just a bucket:

>>> from upath import UPath
>>> bucketpath = UPath('s3://mybucket/')        # trailing slash with bucket only
>>> subpath = bucketpath / 'subfolder/myfile.txt'
>>> subpath
S3Path('s3://mybucket/subfolder/myfile.txt')

Bucket and key but no trailing slash:

>>> from upath import UPath
>>> bucket_with_key = UPath('s3://mybucket/withkey')  # bucket and key but no trailing slash
>>> subpath_new = bucket_with_key / 'subfolder/myfile.txt'
>>> subpath_new
S3Path('s3://mybucket/withkey/subfolder/myfile.txt')

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions