Merge pull request #1938 from Dune-jr/feature-sanitize-filenames

Sanitize gametypes with str_sanitize_filename
This commit is contained in:
oy 2018-12-30 23:47:02 +01:00 committed by GitHub
commit bf97055503
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -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)
{

View file

@ -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.

View file

@ -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;