sindresorhus / filenamify

Convert a string to a valid safe filename
MIT License
489 stars 26 forks source link

Account for extension length when truncating filename #31

Closed tomasklaen closed 2 years ago

tomasklaen commented 2 years ago

I wasn't sure what to do with the filename when extension is loner than maxLength, as removing it completely would create a dotfile which might have unintended consequences, so I decided to keep at least 1 character of the filename in place.


Also found another bug: filenamify doesn't account for dotfiles, so this test:

t.is(filenamify('.asdfghjkl', {maxLength: 2}), '.asdfghjkl');

Can't pass as other parts of filenamify remove the leading dot as they consider it a relative path, and than truncation later on treats it as a filename.

Separate PR? :)

sindresorhus commented 2 years ago

Separate PR? :)

👍