mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-09-15 22:57:24 -04:00
Sanitize filenames from clients in NetworkServer
This commit is contained in:
1 parent
b5f46e3f1d
commit
003c3e0af1
3 files changed
+41
-11
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user