]> granicus.if.org Git - php/commitdiff
- Restore basename in filename on non Windows OS
authorFelipe Pena <felipe@php.net>
Sun, 12 Jun 2011 15:15:44 +0000 (15:15 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 12 Jun 2011 15:15:44 +0000 (15:15 +0000)
ext/mbstring/mbstring.c
main/rfc1867.c

index 0417fafffa270c4adeb15b8e610223e828da7b58..34644a553bc61cf6bf04eb1bbb62afa1413419e4 100644 (file)
@@ -1146,7 +1146,7 @@ static char *php_mb_rfc1867_getword_conf(const zend_encoding *encoding, char *st
 
 static char *php_mb_rfc1867_basename(const zend_encoding *encoding, char *filename TSRMLS_DC) /* {{{ */
 {
-       char *s, *tmp;
+       char *s, *s2, *tmp;
        const size_t filename_len = strlen(filename);
 
        /* The \ check should technically be needed for win32 systems only where
@@ -1155,11 +1155,18 @@ static char *php_mb_rfc1867_basename(const zend_encoding *encoding, char *filena
         * the user does basename() they get a bogus file name. Until IE's user base drops
         * to nill or problem is fixed this code must remain enabled for all systems. */
        s = php_mb_safe_strrchr_ex(filename, '\\', filename_len, (const mbfl_encoding *)encoding);
-       if ((tmp = php_mb_safe_strrchr_ex(filename, '/', filename_len, (const mbfl_encoding *)encoding)) > s) {
-               s = tmp;
-       }
-       if (s) {
-               return s + 1;
+       s2 = php_mb_safe_strrchr_ex(filename, '/', filename_len, (const mbfl_encoding *)encoding);
+       
+       if (s && s2) {
+               if (s > s2) {
+                       return ++s;
+               } else {
+                       return ++s2;
+               }
+       } else if (s) {
+               return ++s;
+       } else if (s2) {
+               return ++s2;
        } else {
                return filename;
        }
index 4decaec39bba2c8bbfecc3400f4d8db422d2ab25..4467aaff160e8e510d4117625e43b6427f64f22d 100644 (file)
@@ -555,17 +555,21 @@ static char *php_ap_getword_conf(const zend_encoding *encoding, char *str TSRMLS
 static char *php_ap_basename(const zend_encoding *encoding, char *path TSRMLS_DC)
 {
        char *s = strrchr(path, '\\');
-       if (s) {
-               char *tmp = strrchr(path, '/');
-               if (tmp && tmp > s) {
-                       s = tmp + 1;
+       char *s2 = strrchr(path, '/');
+       
+       if (s && s2) {
+               if (s > s2) {
+                       ++s;
                } else {
-                       s++;
+                       s = ++s2;
                }
-       } else {
-               s = path;
+               return s;
+       } else if (s) {
+               return ++s;
+       } else if (s2) {
+               return ++s2;
        }
-       return s;
+       return path;
 }
 
 /*