Chonky icon indicating copy to clipboard operation
Chonky copied to clipboard

Wrong output for files with names that contain no "." (period) or file prefix.

Open kolban-google opened this issue 2 years ago • 3 comments

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:

image

and here is what it looks like on screen:

image

What I seem to find is that if my file contains no ".", the display of its name in the file list is "wrong"

kolban-google avatar Apr 22 '22 02:04 kolban-google

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 "".

kolban-google avatar Apr 26 '22 23:04 kolban-google

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 avatar Apr 28 '22 21:04 embeddedt

@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!

ioannistsanaktsidis avatar Mar 21 '23 13:03 ioannistsanaktsidis