Repository navigation
fix: Fixes parsing of relative file:// URLs - #4533
Tomaz-Vieira wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4533 +/- ##
=======================================
Coverage 94.71% 94.71%
=======================================
Files 94 94
Lines 13663 13664 +1
=======================================
+ Hits 12941 12942 +1
Misses 722 722
🚀 New features to boost your workflow:
|
|
you probably didnt lint in the same environment ci runs in, so those type ignores have to come back :/ |
| name = parsed.netloc or None | ||
| if parsed.scheme in ("file", ""): | ||
| name = None | ||
| path = url.removeprefix("file://") |
There was a problem hiding this comment.
dont do string manipulation. we just parsed the url. used the value we got from parsing it
There was a problem hiding this comment.
I don't like it either, but re-joining pieces of the parsed URL is destructive:
>>> urlparse("file://a/b")
ParseResult(scheme='file', netloc='a', path='/b', params='', query='', fragment='')
>>> urlparse("file://a/b?")
ParseResult(scheme='file', netloc='a', path='/b', params='', query='', fragment='')There was a problem hiding this comment.
fwiw "file://a/b" is not a valid file uri. maybe thats part of the issue here
There was a problem hiding this comment.
i did a bit of reading and it seems like fsspec was naughty and treats file://a/b as a relative path starting with a, so we are probably on the hook for continuing to support that, even though its clearly wrong.
try this:
parsed = urlparse(url)
if parsed.scheme == "file":
# RFC 8089: the host is "localhost" or empty. Anything else is a user
# writing a relative path, so fold it back into the path.
host = "" if parsed.netloc == "localhost" else parsed.netloc
path = host + parsed.path
if path == "":
raise ValueError(f"The URL {url!r} has no path. ...")
name = None
elif parsed.scheme:
name = parsed.netloc or None
path = parsed.path.lstrip("/")
else:
name = None
path = parsed.paththen, in LocalStore, make the root absolute. We need to check if anyone is affected downstream of that change.
6133bff to
f9e3641
Compare
Summary
Parsing relative file URLs like
file:://something.zarrwould ultimately deduce a path of"", even causing the weirdest way I've ever deleted my own project directory:For reviewers
The behavior from this PR is definitely more correct than before, and it prevents me from nuking my current directory. I guess one could argue that relative
file://URLs should not be allowed, as I had to ignore the parsing fromurlparse, but if that is the case, then at least I don't thinkStorePath.__str__should be losing the "hostname" from the URL.Author attestation
TODO
Add docstrings and API docs for any new/modified user-facing classes and functionsdocs/user-guide/*.mdchanges/Test coverage is 100%(Codecov passes) (+0.04%)