Chonky
Chonky copied to clipboard
Wrong output for files with names that contain no "." (period) or file prefix.
I seem to find that if I have a file that is made of a string with no "." of file prefix, it is rendered as the name starting with a period.
For example, here is a portion of my file list data:
and here is what it looks like on screen:
What I seem to find is that if my file contains no ".", the display of its name in the file list is "wrong"
After some study, it appears that the error can be found at this source line:
https://github.com/TimboKZ/Chonky/blob/ee9809e2dfa66c4eae56c89b6152d6d2709bdd50/packages/chonky/src/components/file-list/FileEntry-hooks.tsx#L87
If we look at the code found there, we see the following:
const _extname = (fileName: string) => {
const parts = fileName.split('.');
if (parts.length) {
return `.${parts[parts.length - 1]}`;
}
return '';
};
My interpretation of this is that we want to return everything after the last "." so we execute split() on the string using '.' as the splitting character. I believe the original author felt that if "." didn't occur, then an empty array would be returned. This isn't the case, if the '.' does not occur then an array of one element containing the whole string is returned.
This means that if we call _extname("myfile")
then what is returned is ".myfile" rather than "".
I have run into this as well after upgrading to 2.3.2. For now I've rolled back to 2.1.0 where it isn't an issue.
@embeddedt @TimboKZ is it possible to merge this one https://github.com/embeddedt/Chonky/commit/fba34c3049ae19bef650b21f26682b5fccb950c5 to master ? It is very simple and solves the bug mentioned above!