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

ignoring the platforms os.sep, and always using r"/" #12

Closed
bschollnick opened this issue Mar 26, 2020 · 1 comment
Closed

ignoring the platforms os.sep, and always using r"/" #12

bschollnick opened this issue Mar 26, 2020 · 1 comment
Assignees

Comments

@bschollnick
Copy link

As far as I can tell under the Windows platform, the following issues exist:

These are for sanitize_filepath:

  1. The filepath can not start with os.sep (eg. "/users/benjamin/test.zip")

from pathvalidate import sanitize_filepath
sanitize_filepath(r"users\benjamin\test\test1.zip")
'users/benjamin/test/test1.zip'
sanitize_filepath(r"\users\benjamin\test\test1.zip")
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\bschollnick.URMC-SH\python3\av1\lib\site-packages\pathvalidate_filepath.py", line 376, in sanitize_filepath
).sanitize(file_path, replacement_text)
File "C:\Users\bschollnick.URMC-SH\python3\av1\lib\site-packages\pathvalidate_filepath.py", line 74, in sanitize
self.__fpath_validator.validate_abspath(value)
File "C:\Users\bschollnick.URMC-SH\python3\av1\lib\site-packages\pathvalidate_filepath.py", line 206, in validate_abspath
raise err_object
pathvalidate.error.ValidationError: reason=MALFORMED_ABS_PATH, target-platform=universal, description=an invalid absolute file path (\users\benjamin\test\test1.zip) for the platform (universal). to avoid the error, specify an appropriate platform correspond with the path format, or 'auto'.

  • sanitize_filepath does not seem to respect the os.sep setting of the platform it is running on:

import os
print(os.sep)
'\'

sanitize_filepath(r"users\benjamin\test\test1.zip")
'users/benjamin/test/test1.zip'

Please note, the string I passed in was using os.sep. What was returned, did not use os.sep.

@thombashi
Copy link
Owner

@bschollnick
Thank you for your report.

The filepath can not start with os.sep (eg. "/users/benjamin/test.zip")

This issue had fixed at pathvalidate 2.2.2:

>>> from pathvalidate import sanitize_filepath
>>> sanitize_filepath(r"\users\benjamin\test\test1.zip")
'/users/benjamin/test/test1.zip'

sanitize_filepath does not seem to respect the os.sep setting of the platform it is running on:

You can get your expected results if you specify the platform argument to "windows" or "auto" to sanitie_filepath.

>>> sanitize_filepath(r"users\benjamin\test\test1.zip", platform="windows")
'users\\benjamin\\test\\test1.zip'
>>> sanitize_filepath(r"users\benjamin\test\test1.zip", platform="auto")
'users\\benjamin\\test\\test1.zip'

In default, sanitize_filepath normalize a file path to be platform-independent.

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