Skip to content

Commit

Permalink
fix: Filesystem::unique_path wasn't using the unicode rectified string (
Browse files Browse the repository at this point in the history
#4203)

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Mar 27, 2024
1 parent 45a91c9 commit 22ef9b2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/libutil/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,24 +507,30 @@ Filesystem::unique_path(string_view model)
// See boost/filesystem/path.hpp
// The only correct way to do this is to do the conversion ourselves
std::wstring modelStr = Strutil::utf8_to_utf16wstring(model);
std::wstring name;
# else
std::string modelStr = model.str();
std::string name;
# endif
static const char chrs[] = "0123456789abcdef";
static std::mt19937 rg { std::random_device {}() };
static std::uniform_int_distribution<size_t> pick(0, 15);
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
std::string name;
while (true) {
name = model.str();
for (size_t i = 0, e = model.size(); i < e; ++i)
name = modelStr;
// Replace the '%' characters in the name with random hex digits
for (size_t i = 0, e = modelStr.size(); i < e; ++i)
if (name[i] == '%')
name[i] = chrs[pick(rg)];
if (!exists(name))
break;
}
# if defined(_WIN32)
return Strutil::utf16_to_utf8(name);
# else
return name;
# endif
#endif
}

Expand Down

1 comment on commit 22ef9b2

@OgreTransporter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug in line 526, see #4210

Please sign in to comment.