Skip to content

Raise ValueError in with_name() for '' and '.' - #604

Open
syahra712 wants to merge 1 commit into
fsspec:mainfrom
syahra712:fix-with-name-empty
Open

syahra712 wants to merge 1 commit into
fsspec:mainfrom
syahra712:fix-with-name-empty

Conversation

@syahra712

Copy link
Copy Markdown
Contributor

with_name("") and with_name(".") don't raise on fsspec-backed paths, while pathlib and local PosixUPath raise ValueError:

>>> UPath("memory:///a/b.txt").with_name("")
MemoryPath('memory:///a/')
>>> UPath("memory:///a/b.txt").with_name(".")
MemoryPath('memory:///a/.')
>>> pathlib.PurePosixPath("/a/b.txt").with_name("")
ValueError: Invalid name ''

So if a computed name ends up empty, you silently get the parent directory back instead of an error. I saw the same with file:// and s3:// paths.

The fix rejects both names in UPath.with_name. ".." is left alone, since pathlib accepts it too.

I added test_with_name_invalid to JoinablePathTests (with a DataPath override). It fails without the change. I ran the data, memory, local, zip, tar and cached implementation tests plus test_core.py, test_extensions.py and tests/pathlib, not the full nox suite. The only failures are the two test_supported_protocols[...abfss://container/a] cases, which fail the same way without this change in my environment. flake8 is clean on the changed files.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant