thombashi / pathvalidate

A Python library to sanitize/validate a string such as filenames/file-paths/etc.
https://pathvalidate.rtfd.io/
MIT License
210 stars 12 forks source link

Trim space and period in Windows #25

Closed eggplants closed 1 year ago

eggplants commented 1 year ago

I would like to trim heading and trailing Space 0x20 && trailing Period 0x2E with sanitize_filename if given platform is Windows.


https://docs.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/file-folder-name-whitespace-characters

File and Folder names that begin or end with the ASCII Space (0x20) will be saved without these characters. File and Folder names that end with the ASCII Period (0x2E) character will also be saved without this character. All other trailing or leading whitespace characters are retained.

thombashi commented 1 year ago

@eggplants sanitize_filename does already trim those characters when the platform is windows: https://github.com/thombashi/pathvalidate/blob/a7467beff3589f00dad58dd38cb48992d63a5854/test/test_filename.py#L543-L545

Did you mean these trim were not working correctly?