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

absolute path bug #16

Closed
TeoKn opened this issue Mar 5, 2021 · 3 comments
Closed

absolute path bug #16

TeoKn opened this issue Mar 5, 2021 · 3 comments

Comments

@TeoKn
Copy link

TeoKn commented Mar 5, 2021

Whereas sanitize_filepath works perfectly for a relative path, it has an unexpected behaviour on absolute paths. It either rises an exception or, when platform is specified as 'auto' or 'Linux', it lefts the string unchanged.

The execution (see sanitize-filepath-bug.pdf) has been run with Python 3.8.5 under Linux (Ubuntu 20.04.2 LTS). I've just installed for the first time pathvalidate today via pip.

@thombashi
Copy link
Owner

thombashi commented Mar 6, 2021

Thank you for your report.

This behavior is expected.
As the description of the error message, it is impossible to create an absolute file path for universal (operating system independent) platform.

@TeoKn
Copy link
Author

TeoKn commented Mar 6, 2021

Thank you for your comment although it does not seem to be about my report. The question is to sanitize a path, not to create it. Moreover, under Unix, Linux, FreeBSD, etc., paths can be created independently of being absolute or relative. (Only file/directory permissions matter.)
There is no reason for sanitize_filepath, when called with platform="Linux" or platform="auto", to return the original path whereas the latter contains shell-reserved characters (please, have a look at In [6] and In [7] of sanitize-filepath-bug.pdf).

In addition, if an absolute path may be problematic for some platforms (certainly not for Linux), sanitize_filepath could return an equivalent relative path.

@thombashi
Copy link
Owner

The question is to sanitize a path, not to create it.

I mean, create a sanitized file path by sanitize_filepath function.

Moreover, under Unix, Linux, FreeBSD, etc., paths can be created independently of being absolute or relative. (Only file/directory permissions matter.)

In sanitize_filepath, platfrom=universal includes Windows. POSIX abspath and Windows abspath are incompatible.

There is no reason for sanitize_filepath, when called with platform="Linux" or platform="auto", to return the original path whereas the latter contains shell-reserved characters

There is a reason. shell-reserved characters like vertical line (|) can be used for file names when creating files outside shells.
You can use replace_symbol function to remove such characters.

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