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

Consider filesystem encoding for length calculations #26

Closed
virlos opened this issue Aug 15, 2022 · 1 comment
Closed

Consider filesystem encoding for length calculations #26

virlos opened this issue Aug 15, 2022 · 1 comment
Labels
Milestone

Comments

@virlos
Copy link

virlos commented Aug 15, 2022

The maximum length for filenames/pathnames - e.g. 255/4096 for linux - is really a byte length constraint. Thus, given a typical scenario, where sys.getfilesystemencoding() returns utf-8, a path can pass validation that cannot be actually created in the system.

>>> import sys, pathvalidate as pv
>>> sys.getfilesystemencoding()
'utf-8'
>>> good = '\u2013' * 85
>>> long = '\u2013' * 86
>>> len(good), len(long)
(85, 86)
>>> pv.validate_filename(good)
>>> pv.validate_filename(long)
>>> pv.validate_filename('a' * 256)
Traceback (most recent call last):
...
pathvalidate.error.InvalidLengthError: filename is too long: expected<=255, actual=256, reason=INVALID_LENGTH

>>> with open(good, 'w') as handle:
...     handle.write('good')
... 
4
>>> with open(long, 'w') as handle:
...     handle.write('long')
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 36] File name too long: '––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––'
@thombashi thombashi added this to the v3 milestone Feb 26, 2023
@thombashi thombashi added the bug label May 21, 2023
@thombashi
Copy link
Owner

Thank you for your report.
The problem was fixed at pathvalidate 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants