From 97d5d659d3f5e30d0db24bf41b64aa864f4efe0f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 31 Jul 2022 17:37:21 +1000 Subject: [PATCH] FileSystem: Fix zeros getting stripped in path --- src/common-tests/path_tests.cpp | 2 ++ src/common/file_system.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common-tests/path_tests.cpp b/src/common-tests/path_tests.cpp index d83addb1d..154c03f11 100644 --- a/src/common-tests/path_tests.cpp +++ b/src/common-tests/path_tests.cpp @@ -230,6 +230,8 @@ TEST(FileSystem, SanitizeFileName) 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"ŻąłóРстуぬねのは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 ASSERT_EQ(Path::SanitizeFileName(u8"foo:"), u8"foo_"); ASSERT_EQ(Path::SanitizeFileName(u8"foo:bar."), u8"foo_bar_"); diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 484f77189..cad448aec 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -60,14 +60,14 @@ static std::time_t ConvertFileTimeToUnixTime(const FILETIME& ft) } #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 // https://docs.microsoft.com/en-gb/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#naming-conventions if ((c == U'/' || c == U'\\') && strip_slashes) 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(31)) { return false; @@ -76,7 +76,11 @@ static inline bool FileSystemCharacterIsSane(char32_t c, bool strip_slashes) if (c == '/' && strip_slashes) return false; - // macos doesn't allow colons, apparently + // drop asterisks too, they make globbing annoying + if (c == '*') + return false; + + // macos doesn't allow colons, apparently #ifdef __APPLE__ if (c == U':') return false;