[vlc-devel] commit: Win32: canonicalize path separator, avoid isalpha(), remove dead code ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Apr 5 18:32:20 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr  5 19:30:30 2009 +0300| [3e481eab44abfa9e94970bb304f191df7fca9451] | committer: 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).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3e481eab44abfa9e94970bb304f191df7fca9451
---

 src/text/strings.c |   44 ++++++--------------------------------------
 1 files changed, 6 insertions(+), 38 deletions(-)

diff --git a/src/text/strings.c b/src/text/strings.c
index 71caaaa..8a0229c 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -1100,16 +1100,10 @@ char* filename_sanitize( const char *str_origin )
  */
 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
     /* 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;
 #endif
     while( *str )
@@ -1118,36 +1112,10 @@ void path_sanitize( char *str )
         if( *str == ':' )
             *str = '_';
 #elif defined( WIN32 )
-        switch( *str )
-        {
-            case '*':
-            case '"':
-            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;
-        }
+        if( strchr( "*\"?:|<>", *str ) )
+            *str = '_';
+        if( *str == '/' )
+            *str = DIR_SEP_CHAR;
 #endif
         str++;
     }




More information about the vlc-devel mailing list