Fix removeWildcards to deal with leading/trailing spaces, and add some more characters to the whilelist while we're at it.

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@8228 4a71c877-e1ca-e34f-864e-861f7616d084
master
Guangcong Luo 2009-10-07 19:02:12 +00:00 committed by Git SVN Gateway
parent bc915b5d2c
commit c4eb169c23
1 changed files with 39 additions and 22 deletions

View File

@ -598,29 +598,28 @@ void removeWildcards(char *pStr)
{ {
UDWORD i; UDWORD i;
for(i=0;i<strlen(pStr);i++) // Remember never to allow: < > : " / \ | ? *
{
/* if( pStr[i] == '?'
|| pStr[i] == '*'
|| pStr[i] == '"'
|| pStr[i] == '.'
|| pStr[i] == '/'
|| pStr[i] == '\\'
|| pStr[i] == '|' )
{
pStr[i] = '_';
}
*/
if( !isalnum(pStr[i])
&& pStr[i] != ' '
&& pStr[i] != '-'
&& pStr[i] != '+'
&& pStr[i] != '!'
)
{
pStr[i] = '_';
}
// Whitelist: Get rid of any characters except:
// a-z A-Z 0-9 - + ! , = ^ @ # $ % & ' ( ) [ ] (and space)
for (i=0; i<strlen(pStr); i++)
{
if (!isalnum(pStr[i])
&& (pStr[i] != ' ' || i==0 || pStr[i-1]==' ')
// We allow spaces as long as they aren't the first char, or two spaces in a row
&& pStr[i] != '-'
&& pStr[i] != '+'
&& pStr[i] != '!'
&& pStr[i] != ','
&& pStr[i] != '='
&& pStr[i] != '^'
&& pStr[i] != '@'
&& (pStr[i]<35 || pStr[i]>41) // # $ % & ' ( )
&& pStr[i] != '[' && pStr[i] != ']'
)
{
pStr[i] = '_';
}
} }
if (strlen(pStr) >= MAX_SAVE_NAME) if (strlen(pStr) >= MAX_SAVE_NAME)
@ -628,6 +627,24 @@ void removeWildcards(char *pStr)
pStr[MAX_SAVE_NAME - 1] = 0; pStr[MAX_SAVE_NAME - 1] = 0;
} }
// Trim trailing spaces
for (i=strlen(pStr)-1; pStr[i]==' ' && i>=0; i--);
pStr[i+1] = 0;
// Trims leading spaces (currently unused)
/* for (i=0; pStr[i]==' '; i++);
if (i != 0)
{
memmove(pStr, pStr+i, strlen(pStr)+1-i);
} */
// If that leaves us with a blank string, replace with '!'
if (pStr[0] == 0)
{
pStr[0] = '!';
pStr[1] = 0;
}
return; return;
} }