Bug summary
Using FilePath with a relative path strips the first character of the filename in name and parts.
Reproduction
from upath.implementations.local import FilePath
from upath import UPath
fp = FilePath("relative/path.zip")
print(fp.name) # actual: "ath.zip"
print(fp.parts) # actual: ("/", "relative", "ath.zip")
up = UPath("relative/path.zip")
print(up.name) # actual: "path.zip"
print(up.parts) # actual: ("relative", "path.zip")
Expected
FilePath("relative/path.zip").name == "path.zip"
FilePath("relative/path.zip").parts == ("relative", "path.zip")
All relative paths affected
| Path |
Expected .name |
Actual .name |
a/b.txt |
b.txt |
.txt |
./relative/path.zip |
path.zip |
ath.zip |
../parent/file.txt |
file.txt |
ile.txt |
single.txt |
single.txt |
ingle.txt |
deep/nested/path/file.doc |
file.doc |
ile.doc |
Exactly 1 character is always truncated from the filename.
Notes / hypothesis
I believe the issue is in WrappedFileSystemFlavour.split() (upath/_flavour.py).
For relative paths, parent() returns a head with a leading / while stripped_path does not, leading to an off-by-one when slicing the tail.
Example debug:
head = "/relative" # len = 9
stripped_path = "relative/path.zip"
tail = stripped_path[len(head) + 1:] # "ath.zip"
Environment
- universal-pathlib: 0.3.8
- Python: 3.12
- OS: macOS (likely affects Linux too)
Related
Bug summary
Using
FilePathwith a relative path strips the first character of the filename innameandparts.Reproduction
Expected
All relative paths affected
.name.namea/b.txtb.txt.txt./relative/path.zippath.zipath.zip../parent/file.txtfile.txtile.txtsingle.txtsingle.txtingle.txtdeep/nested/path/file.docfile.docile.docExactly 1 character is always truncated from the filename.
Notes / hypothesis
I believe the issue is in
WrappedFileSystemFlavour.split()(upath/_flavour.py).For relative paths,
parent()returns a head with a leading/whilestripped_pathdoes not, leading to an off-by-one when slicing the tail.Example debug:
Environment
Related
split()).parentsreturns an empty path as the last element #525 (parent/parts issues)