Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening absolute paths to folders containing exclamation marks fails #562

Open
FirefoxMetzger opened this issue Jan 28, 2023 · 4 comments
Open

Comments

@FirefoxMetzger
Copy link

I know that using special characters in path names is asking for trouble, but I like to prefix active projects with an exclamation mark (!) because it makes them show up at the top when ordered alphabetically. This is incredibly useful when you have a lot of projects.

As a result, I found this by accident while playing with a downstream library:

>>> import fs
>>> fs.__version__
'2.4.16'
>>> weird_path = 'C:\\Users\\Sebastian\\Documents\\Coding-Projects\\!deploy_test\\foo'
>>> fs.open_fs(weird_path)
OSFS('C:\\Users\\Sebastian\\Documents\\Coding-Projects')

However, running the same using a relative path resolves as expected:

>>> import os
>>> os.getcwd()
'C:\\Users\\Sebastian\\Documents\\Coding-Projects\\!deploy_test'
>>> fs.open_fs("./foo")
OSFS('C:\\Users\\Sebastian\\Documents\\Coding-Projects\\!deploy_test\\foo')

Is there a workaround for this behavior? I'm eager to have this fixed quickly, so if there is no workaround I could attempt a PR assuming this would lead to a reasonably fast release of the bugfix :)

@FirefoxMetzger
Copy link
Author

_RE_FS_URL = re.compile(
r"""
^
(.*?)
:\/\/
(?:
(?:(.*?)@(.*?))
|(.*?)
)
(?:
!(.*?)$
)*$
""",
re.VERBOSE,
)

This is why the above breaks. Why are we testing for ! to separate url2 and path in line 53?

@FirefoxMetzger
Copy link
Author

A current workaround is to percent-encode the !

>>> import fs
>>> weird_path = 'C:\\Users\\Sebastian\\Documents\\Coding-Projects\\%21deploy_test\\foo' 
>>> fs.open_fs(weird_path)
OSFS('C:\\Users\\Sebastian\\Documents\\Coding-Projects\\!deploy_test\\foo')

@lurch
Copy link
Contributor

lurch commented Jan 28, 2023

Coincidentally, the comments in #561 seem relevant here too!
I believe if you just used the regular OSFS constructor, rather than the open_fs helper-method, then that would stop the ! from being treated specially?

(EDIT: open_fs expects FS URLs, rather than FS paths, which explains why you need to percent-encode the !)

@FirefoxMetzger
Copy link
Author

FirefoxMetzger commented Jan 29, 2023

(EDIT: open_fs expects FS URLs, rather than FS paths, which explains why you need to percent-encode the !)

Fair point. If this is expected behavior, could we add a note in the docs? It took me some time to figure out, so I'd expect to not be the only one who trips over this behavior.

I believe if you just used the regular OSFS constructor, rather than the open_fs helper-method, then that would stop the ! from being treated specially?

This would limit us to OSFS only, right? The open_fs helper parses the schema so you could have non-local storage types, too. For my personal use case, that doesn't matter and local-only is fine. In the general case, I think it won't hold.

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

No branches or pull requests

2 participants