mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge pull request #1938 from Dune-jr/feature-sanitize-filenames
Sanitize gametypes with str_sanitize_filename
This commit is contained in:
commit
bf97055503
|
@ -1793,6 +1793,22 @@ void str_sanitize(char *str_in)
|
|||
}
|
||||
}
|
||||
|
||||
/* removes all forbidden windows/unix characters in filenames*/
|
||||
char* str_sanitize_filename(char* aName)
|
||||
{
|
||||
char *str = (char *)aName;
|
||||
while(*str)
|
||||
{
|
||||
// replace forbidden characters with a whispace
|
||||
if(*str == '/' || *str == '<' || *str == '>' || *str == ':' || *str == '"'
|
||||
|| *str == '/' || *str == '\\' || *str == '|' || *str == '?' || *str == '*')
|
||||
*str = ' ';
|
||||
str++;
|
||||
}
|
||||
str_clean_whitespaces(aName);
|
||||
return aName;
|
||||
}
|
||||
|
||||
/* removes leading and trailing spaces and limits the use of multiple spaces */
|
||||
void str_clean_whitespaces(char *str_in)
|
||||
{
|
||||
|
|
|
@ -826,6 +826,19 @@ void str_sanitize_cc(char *str);
|
|||
*/
|
||||
void str_sanitize(char *str);
|
||||
|
||||
/*
|
||||
Function: str_sanitize_filename
|
||||
Replaces all forbidden Windows/Unix characters with whitespace
|
||||
or nothing if leading or trailing.
|
||||
|
||||
Parameters:
|
||||
str - String to sanitize.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-terminated strings.
|
||||
*/
|
||||
char* str_sanitize_filename(char* aName);
|
||||
|
||||
/*
|
||||
Function: str_check_pathname
|
||||
Check if the string contains '..' (parent directory) paths.
|
||||
|
|
|
@ -2132,11 +2132,15 @@ void CMenus::RenderServerbrowserBottomBox(CUIRect MainView)
|
|||
}
|
||||
void CMenus::DoGameIcon(const char *pName, const CUIRect *pRect, int Type)
|
||||
{
|
||||
char aNameBuf[128];
|
||||
str_copy(aNameBuf, pName, sizeof(aNameBuf));
|
||||
str_sanitize_filename(aNameBuf);
|
||||
|
||||
// get texture
|
||||
IGraphics::CTextureHandle Tex = m_GameIconDefault;
|
||||
for(int i = 0; i < m_lGameIcons.size(); ++i)
|
||||
{
|
||||
if(!str_comp_nocase(pName, m_lGameIcons[i].m_Name))
|
||||
if(!str_comp_nocase(aNameBuf, m_lGameIcons[i].m_Name))
|
||||
{
|
||||
Tex = m_lGameIcons[i].m_IconTexture;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue