fsspec / fsspec/filesystem_spec
Handling of URL quoting (for `file://` URLs)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 490
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 38
Description
I have a local file at /tmp/URL--https&c%%zenodo.org%record%68331 that I am trying to access via FSSPEC. This fails due to a missing unquoting step, as far as I can tell.
Here is a small demo to show the essence of the issue:
>>> from pathlib import Path
>>> from fsspec.core import url_to_fs
# local file exists
>>> p = Path('/tmp/URL--https&c%%zenodo.org%record%68331')
>>> p.exists()
True
# file:// URL generation via pathlib
>>> p_url = p.as_uri()
# this quotes the URL, which is to be expected
>>> p_url
'file:///tmp/URL--https%26c%25%25zenodo.org%25record%2568331'
# fsspec does not unquote
>>> fs, urlpath = url_to_fs(p_url)
>>> urlpath
'/tmp/URL--https%26c%25%25zenodo.org%25record%2568331'
# the returned urlpath is not the original path
# (this may be OK still)
>>> Path(urlpath).exists()
False
# but fsspec also fails to access the target file
>>> fs.stat(urlpath)
-> FileNotFoundError: [Errno 2] No such file or directory: '/tmp/URL--https%26c%25%25zenodo.org%25record%2568331'
# if quoting is undone, either for the URL, or for the path, things start working
>>> from urllib.parse import unquote
>>> fs.stat(unquote(urlpath))
{'name': '/tmp/URL--https&c%%zenodo.org%record%68331',...}
# or the URL
>>> fs, urlpath = url_to_fs(unquote(p_url))
>>> fs.stat(urlpath)
{'name': '/tmp/URL--https&c%%zenodo.org%record%68331',...}
I was confused by the above behavior, as I expect the urlpath returned by url_to_fs() to match the needs of the simultaneously returned fs object. My expectation was that fsspec would assume all input URL to be adequately quoted, and do any necessary unquoting to match the nature of urlpath to the needs of fs internally.
Do you consider this behavior a bug?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example through fsspec.core.url_to_fs() and the returned filesystem's fs.stat() call, comparing quoted and unquoted file:// paths. Trace how the URL path is parsed and passed to the filesystem; done means a pathlib-generated file:// URL resolves to the existing local file without requiring callers to unquote it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100