Commit 3e481eab authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Win32: canonicalize path separator, avoid isalpha(), remove dead code

In principle, isalpha() depends on the locale. As for directory
traversal, we should either add a boolean, or fix it manually in the
caller (on a case-by-case basis).
parent beb42fb1
...@@ -1100,16 +1100,10 @@ char* filename_sanitize( const char *str_origin ) ...@@ -1100,16 +1100,10 @@ char* filename_sanitize( const char *str_origin )
*/ */
void path_sanitize( char *str ) void path_sanitize( char *str )
{ {
#if 0
/*
* Uncomment the two blocks to prevent /../ or /./, i'm not sure that we
* want to.
*/
char *prev = str - 1;
#endif
#ifdef WIN32 #ifdef WIN32
/* check drive prefix if path is absolute */ /* check drive prefix if path is absolute */
if( isalpha(*str) && (':' == *(str+1)) ) if( (((unsigned char)(str[0] - 'A') < 26)
|| ((unsigned char)(str[0] - 'a') < 26)) && (':' == str[1]) )
str += 2; str += 2;
#endif #endif
while( *str ) while( *str )
...@@ -1118,36 +1112,10 @@ void path_sanitize( char *str ) ...@@ -1118,36 +1112,10 @@ void path_sanitize( char *str )
if( *str == ':' ) if( *str == ':' )
*str = '_'; *str = '_';
#elif defined( WIN32 ) #elif defined( WIN32 )
switch( *str ) if( strchr( "*\"?:|<>", *str ) )
{ *str = '_';
case '*': if( *str == '/' )
case '"': *str = DIR_SEP_CHAR;
case '?':
case ':':
case '|':
case '<':
case '>':
*str = '_';
}
#endif
#if 0
if( *str == '/'
#ifdef WIN32
|| *str == '\\'
#endif
)
{
if( str - prev == 2 && prev[1] == '.' )
{
prev[1] = '.';
}
else if( str - prev == 3 && prev[1] == '.' && prev[2] == '.' )
{
prev[1] = '_';
prev[2] = '_';
}
prev = str;
}
#endif #endif
str++; str++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment