Sanitize filenames from clients in NetworkServer

This commit is contained in:
Adam Honse committed 2026-07-31 19:01:25 -05:00
1 parent b5f46e3f1d
commit 003c3e0af1
3 files changed
+41 -11

No files matched your search

+28
View File
@@ -38,3 +38,31 @@ const char* StringUtils::wchar_to_char(const wchar_t* pwchar)
return filePathC;
}
std::string StringUtils::make_filename(std::string input)
{
/*-----------------------------------------------------*\
| Replace : characters with - characters |
\*-----------------------------------------------------*/
input = std::regex_replace(input, std::regex(":"), "-");
/*-----------------------------------------------------*\
| Remove all other characters |
\*-----------------------------------------------------*/
input = std::regex_replace(input, std::regex("[#%&\\{\\}\\\\<>\\*\\?/!`';@+|=]"), "");
/*-----------------------------------------------------*\
| Remove leading . characters |
\*-----------------------------------------------------*/
input = std::regex_replace(input, std::regex("^\\.+"), "");
/*-----------------------------------------------------*\
| Remove control characters |
\*-----------------------------------------------------*/
input = std::regex_replace(input, std::regex("[\\x00-\\x1F\\x7F]"), "");
/*-----------------------------------------------------*\
| Return complete string |
\*-----------------------------------------------------*/
return(input);
}