mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-18 06:25:37 +00:00
FileSystem: Fix zeros getting stripped in path
This commit is contained in:
parent
3505ca26e0
commit
97d5d659d3
|
@ -230,6 +230,8 @@ TEST(FileSystem, SanitizeFileName)
|
||||||
ASSERT_EQ(Path::SanitizeFileName(u8"foo/bar"), u8"foo_bar");
|
ASSERT_EQ(Path::SanitizeFileName(u8"foo/bar"), u8"foo_bar");
|
||||||
ASSERT_EQ(Path::SanitizeFileName(u8"f🙃o"), u8"f🙃o");
|
ASSERT_EQ(Path::SanitizeFileName(u8"f🙃o"), u8"f🙃o");
|
||||||
ASSERT_EQ(Path::SanitizeFileName(u8"ŻąłóРстуぬねのはen🍪⟑η∏☉ⴤℹ︎∩₲ ₱⟑♰⫳🐱"), u8"ŻąłóРстуぬねのはen🍪⟑η∏☉ⴤℹ︎∩₲ ₱⟑♰⫳🐱");
|
ASSERT_EQ(Path::SanitizeFileName(u8"ŻąłóРстуぬねのはen🍪⟑η∏☉ⴤℹ︎∩₲ ₱⟑♰⫳🐱"), u8"ŻąłóРстуぬねのはen🍪⟑η∏☉ⴤℹ︎∩₲ ₱⟑♰⫳🐱");
|
||||||
|
ASSERT_EQ(Path::SanitizeFileName(u8"abcdefghijlkmnopqrstuvwxyz-0123456789+&=_[]{}"), u8"abcdefghijlkmnopqrstuvwxyz-0123456789+&=_[]{}");
|
||||||
|
ASSERT_EQ(Path::SanitizeFileName(u8"some*path**with*asterisks"), u8"some_path__with_asterisks");
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ASSERT_EQ(Path::SanitizeFileName(u8"foo:"), u8"foo_");
|
ASSERT_EQ(Path::SanitizeFileName(u8"foo:"), u8"foo_");
|
||||||
ASSERT_EQ(Path::SanitizeFileName(u8"foo:bar."), u8"foo_bar_");
|
ASSERT_EQ(Path::SanitizeFileName(u8"foo:bar."), u8"foo_bar_");
|
||||||
|
|
|
@ -60,14 +60,14 @@ static std::time_t ConvertFileTimeToUnixTime(const FILETIME& ft)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline bool FileSystemCharacterIsSane(char32_t c, bool strip_slashes)
|
__declspec(noinline) static inline bool FileSystemCharacterIsSane(char32_t c, bool strip_slashes)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// https://docs.microsoft.com/en-gb/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#naming-conventions
|
// https://docs.microsoft.com/en-gb/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#naming-conventions
|
||||||
if ((c == U'/' || c == U'\\') && strip_slashes)
|
if ((c == U'/' || c == U'\\') && strip_slashes)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (c == U'<' || c == U'>' || c == U':' || c == U'"' || c == U'|' || c == U'?' || c == U'*' || c == U'0' ||
|
if (c == U'<' || c == U'>' || c == U':' || c == U'"' || c == U'|' || c == U'?' || c == U'*' || c == 0 ||
|
||||||
c <= static_cast<char32_t>(31))
|
c <= static_cast<char32_t>(31))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -76,6 +76,10 @@ static inline bool FileSystemCharacterIsSane(char32_t c, bool strip_slashes)
|
||||||
if (c == '/' && strip_slashes)
|
if (c == '/' && strip_slashes)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// drop asterisks too, they make globbing annoying
|
||||||
|
if (c == '*')
|
||||||
|
return false;
|
||||||
|
|
||||||
// macos doesn't allow colons, apparently
|
// macos doesn't allow colons, apparently
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (c == U':')
|
if (c == U':')
|
||||||
|
|
Loading…
Reference in a new issue