`MakeFileName()` creates hidden file in case `base_name` is empty.
Describe the bug
The current version of function MakeFIleName() in FilePath API doesn't check if the base_name is empty or not. In case the number passed to the function is 0 then MakeFileName() function will create path for hidden files in *nix systems which is something that we don't want.
Steps to reproduce the bug
You don't need to reproduce the bug in your side because it's readily visible in the function MakeFileName()
FilePath FilePath::MakeFileName(const FilePath& directory,
const FilePath& base_name, int number,
const char* extension) {
std::string file;
if (number == 0) {
file = base_name.string() + "." + extension;
} else {
file =
base_name.string() + "_" + StreamableToString(number) + "." + extension;
}
return ConcatPaths(directory, FilePath(file));
}
Possible solution
We need to substitute base_name with a random string or just unknown file in case base_name is empty.
Does the bug persist in the most recent commit?
Yes
What operating system and version are you using?
Ubuntu 20.04.4 LTS
What compiler and version are you using?
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
What build system are you using?
cmake version 3.22.1
@derekmauro Tell me if you are open to accepting a PR that fixes this issue.
This seems WAI to us, but we might consider having a patch that special cases empty filenames. Could you please explain how you encountered this issue?
Could you please explain how you encountered this issue?
@dinord Personally I didn't encounter this issue but it may become an issue in case base_name is empty. I was just reading the code of FilePath API and found that empty base_name is not handled properly. What do you say? How it should be fixed?