colder          Tue Jul  8 22:40:30 2008 UTC

  Modified files:              
    /php-src/ext/spl    spl_directory.c 
    /php-src/ext/spl/tests      dit_001.phpt fileobject_003.phpt 
                                fileobject_004.phpt 
                                fileobject_getfileinfo_basic.phpt 
  Log:
  - Fix filename in debug_info
  - Fix #45345 (getPathInfo on the file instead of the dir)
  - Remove trailing / on input
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.157&r2=1.158&diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.157 
php-src/ext/spl/spl_directory.c:1.158
--- php-src/ext/spl/spl_directory.c:1.157       Wed Jul  2 10:46:52 2008
+++ php-src/ext/spl/spl_directory.c     Tue Jul  8 22:40:29 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_directory.c,v 1.157 2008/07/02 10:46:52 tony2001 Exp $ */
+/* $Id: spl_directory.c,v 1.158 2008/07/08 22:40:29 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -374,29 +374,47 @@
        intern->file_name = use_copy ? ezstrndup(type, path, len) : path;
        intern->file_name_len = len;
 
-       if (type == IS_UNICODE) {
-               p1.u = u_strrchr(path.u, '/');
-       } else {
-               p1.s = strrchr(path.s, '/');
-       }
+       while (1) {
+               if (type == IS_UNICODE) {
+                       p1.u = u_strrchr(intern->file_name.u, '/');
+               } else {
+                       p1.s = strrchr(intern->file_name.s, '/');
+               }
 #if defined(PHP_WIN32) || defined(NETWARE)
-       if (type == IS_UNICODE) {
-               p2.u = u_strrchr(path.u, '\\');
-       } else {
-               p2.s = strrchr(path.s, '\\');
-       }
+               if (type == IS_UNICODE) {
+                       p2.u = u_strrchr(intern->file_name.u, '\\');
+               } else {
+                       p2.s = strrchr(intern->file_name.s, '\\');
+               }
 #else
-       p2.v = 0;
+               p2.v = 0;
 #endif
-       if (p1.v || p2.v) {
-               if (type == IS_UNICODE) {
-                       intern->_path_len = (p1.u > p2.u ? p1.u : p2.u) - 
path.u;
+               if (p1.v || p2.v) {
+                       zstr slash_pos;
+                       
+                       if (type == IS_UNICODE) {
+                               slash_pos.u = (p1.u > p2.u ? p1.u : p2.u);
+                               if (IS_SLASH_AT(type, intern->file_name, 
intern->file_name_len)) {
+                                       intern->file_name_len = slash_pos.u - 
intern->file_name.u;
+                                       
intern->file_name.u[intern->file_name_len] = 0;
+                                       continue;
+                               }
+                               intern->_path_len = slash_pos.u - 
intern->file_name.u;
+                       } else {
+                               slash_pos.s = (p1.s > p2.s ? p1.s : p2.s);
+                               if (IS_SLASH_AT(type, intern->file_name, 
intern->file_name_len)) {
+                                       intern->file_name_len = slash_pos.s - 
intern->file_name.s;
+                                       
intern->file_name.s[intern->file_name_len] = 0;
+                                       continue;
+                               }
+                               intern->_path_len = slash_pos.s - 
intern->file_name.s;
+                       }
                } else {
-                       intern->_path_len = (p1.s > p2.s ? p1.s : p2.s) - 
path.s;
+                       intern->_path_len = 0;
                }
-       } else {
-               intern->_path_len = 0;
+               break;
        }
+
        intern->_path_type = type;
        intern->_path = ezstrndup(type, path, intern->_path_len);
 } /* }}} */
@@ -542,6 +560,27 @@
 }
 /* }}} */
 
+static zstr spl_filesystem_object_get_pathname(spl_filesystem_object *intern, 
int *len, zend_uchar *type  TSRMLS_DC) { /* {{{ */
+       switch (intern->type) {
+       case SPL_FS_INFO:
+       case SPL_FS_FILE:
+               *len = intern->file_name_len;
+               *type = intern->file_name_type;
+               return intern->file_name;
+       case SPL_FS_DIR:
+               if (intern->u.dir.entry.d_name[0]) {
+                       spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+                       *len = intern->file_name_len;
+                       *type = intern->file_name_type;
+                       return intern->file_name;
+               }
+       }
+       *len  = 0;
+       *type = IS_STRING;
+       return intern->file_name; /* dummy */
+}
+/* }}} */
+
 static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp 
TSRMLS_DC) /* {{{{ */
 {
        spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(obj TSRMLS_CC);
@@ -564,13 +603,23 @@
 
        zend_hash_copy(rv, intern->std.properties, (copy_ctor_func_t) 
zval_add_ref, (void *) &tmp, sizeof(zval *));
 
-       path = spl_filesystem_object_get_path(intern, &path_len, &path_type 
TSRMLS_CC);
+       path = spl_filesystem_object_get_pathname(intern, &path_len, &path_type 
TSRMLS_CC);
        pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", 
sizeof("pathName")-1, &pnlen TSRMLS_CC);
        add_u_assoc_zstrl_ex(&zrv, ZEND_STR_TYPE, pnstr, pnlen+1, path_type, 
path, path_len, 1);
        efree(pnstr.v);
        if (intern->file_name.v) {
                pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, 
"fileName", sizeof("fileName")-1, &pnlen TSRMLS_CC);
-               add_u_assoc_zstrl_ex(&zrv, ZEND_STR_TYPE, pnstr, pnlen+1, 
intern->file_name_type, intern->file_name, intern->file_name_len, 1);
+               path = spl_filesystem_object_get_path(intern, &path_len, 
&path_type TSRMLS_CC);
+               if (path_len && path_len < intern->file_name_len) {
+                       if (intern->file_name_type == IS_UNICODE) {
+                               path.u = intern->file_name.u + path_len + 1;
+                       } else {
+                               path.s = intern->file_name.s + path_len + 1;
+                       }
+                       add_u_assoc_zstrl_ex(&zrv, ZEND_STR_TYPE, pnstr, 
pnlen+1, intern->file_name_type, path, intern->file_name_len - (path_len + 1), 
1);
+               } else {
+                       add_u_assoc_zstrl_ex(&zrv, ZEND_STR_TYPE, pnstr, 
pnlen+1, intern->file_name_type, intern->file_name, intern->file_name_len, 1);
+               }
                efree(pnstr.v);
        }
        if (intern->type == SPL_FS_DIR) {
@@ -849,16 +898,13 @@
 SPL_METHOD(SplFileInfo, getPathname)
 {
        spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+       zstr       path;
+       zend_uchar path_type;
+       int        path_len;
 
-       switch (intern->type) {
-       case SPL_FS_INFO:
-       case SPL_FS_FILE:
-               RETURN_ZSTRL(intern->file_name_type, intern->file_name, 
intern->file_name_len, ZSTR_DUPLICATE);
-       case SPL_FS_DIR:
-               if (intern->u.dir.entry.d_name[0]) {
-                       spl_filesystem_object_get_file_name(intern TSRMLS_CC);
-                       RETURN_ZSTRL(intern->file_name_type, intern->file_name, 
intern->file_name_len, ZSTR_DUPLICATE);
-               }
+       path = spl_filesystem_object_get_pathname(intern, &path_len, &path_type 
TSRMLS_CC);
+       if (path_len) {
+               RETURN_ZSTRL(path_type, path, path_len, ZSTR_DUPLICATE);
        }
        RETURN_BOOL(0);
 }
@@ -1200,8 +1246,10 @@
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == 
SUCCESS) {
                zend_uchar path_type;
                int path_len;
-               zstr path = spl_filesystem_object_get_path(intern, &path_len, 
&path_type TSRMLS_CC);
-               spl_filesystem_object_create_info(intern, path_type, path, 
path_len, 1, ce, return_value TSRMLS_CC);
+               zstr path = spl_filesystem_object_get_pathname(intern, 
&path_len, &path_type TSRMLS_CC);
+               if (path_len) {
+                       spl_filesystem_object_create_info(intern, path_type, 
path, path_len, 1, ce, return_value TSRMLS_CC);
+               }
        }
 
        php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/dit_001.phpt?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/spl/tests/dit_001.phpt
diff -u php-src/ext/spl/tests/dit_001.phpt:1.7 
php-src/ext/spl/tests/dit_001.phpt:1.8
--- php-src/ext/spl/tests/dit_001.phpt:1.7      Sat May 24 14:11:59 2008
+++ php-src/ext/spl/tests/dit_001.phpt  Tue Jul  8 22:40:30 2008
@@ -10,9 +10,11 @@
 ?>
 ===DONE===
 --EXPECTF--
-object(DirectoryIterator)#%d (3) {
+object(DirectoryIterator)#%d (4) {
   %s"pathName"%s"SplFileInfo":private]=>
-  %s(1) "."
+  %s(%d) "./%s"
+  %s"fileName"%s"SplFileInfo":private]=>
+  %s(%d) "%s"
   %s"glob"%s"DirectoryIterator":private]=>
   bool(false)
   %s"subPathName"%s"RecursiveDirectoryIterator":private]=>
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fileobject_003.phpt?r1=1.8&r2=1.9&diff_format=u
Index: php-src/ext/spl/tests/fileobject_003.phpt
diff -u php-src/ext/spl/tests/fileobject_003.phpt:1.8 
php-src/ext/spl/tests/fileobject_003.phpt:1.9
--- php-src/ext/spl/tests/fileobject_003.phpt:1.8       Tue May 27 02:55:51 2008
+++ php-src/ext/spl/tests/fileobject_003.phpt   Tue Jul  8 22:40:30 2008
@@ -47,13 +47,13 @@
   [u"pathName":u"SplFileInfo":private]=>
   unicode(%d) "%s"
   [u"fileName":u"SplFileInfo":private]=>
-  unicode(%d) "%sfileobject_001a.txt"
+  unicode(%d) "fileobject_001a.txt"
 }
 object(SplFileInfo)#%d (2) {
   [u"pathName":u"SplFileInfo":private]=>
   unicode(%d) "%s"
   [u"fileName":u"SplFileInfo":private]=>
-  unicode(%d) "%sfileobject_001a.txt"
+  unicode(%d) "fileobject_001a.txt"
 }
 bool(false)
 bool(true)
@@ -63,7 +63,7 @@
 bool(true)
 unicode(19) "fileobject_001a.txt"
 bool(true)
-unicode(%d) "%stests"
+string(%d) "%stests"
 bool(true)
 unicode(%d) "%sfileobject_001a.txt"
 unicode(19) "fileobject_001a.txt"
@@ -73,13 +73,13 @@
   [u"pathName":u"SplFileInfo":private]=>
   unicode(%d) "%s"
   [u"fileName":u"SplFileInfo":private]=>
-  unicode(%d) "%s"
+  unicode(%d) ""
 }
 object(SplFileInfo)#%d (2) {
   [u"pathName":u"SplFileInfo":private]=>
   unicode(%d) "%s"
   [u"fileName":u"SplFileInfo":private]=>
-  unicode(%d) "%s"
+  unicode(%d) ""
 }
 bool(false)
 bool(true)
@@ -89,7 +89,7 @@
 bool(true)
 unicode(5) "tests"
 bool(true)
-unicode(%d) "%sspl"
+string(%d) "%sspl"
 bool(true)
 unicode(%d) "%stests"
 unicode(%d) "%stests"
@@ -115,7 +115,7 @@
 bool(true)
 unicode(%d) "tests"
 bool(true)
-unicode(%d) "%sspl"
+string(%d) "%sspl"
 bool(true)
 unicode(%d) "%stests"
 unicode(5) "tests"
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fileobject_004.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/spl/tests/fileobject_004.phpt
diff -u php-src/ext/spl/tests/fileobject_004.phpt:1.3 
php-src/ext/spl/tests/fileobject_004.phpt:1.4
--- php-src/ext/spl/tests/fileobject_004.phpt:1.3       Fri Jun 13 00:18:57 2008
+++ php-src/ext/spl/tests/fileobject_004.phpt   Tue Jul  8 22:40:30 2008
@@ -16,7 +16,7 @@
 ?>
 ==DONE==
 --EXPECTF--
-unicode(%d) "%sspl%stests"
-unicode(19) "fileobject_004.phpt"
-unicode(%d) "%sspl%stests%sfileobject_004.phpt"
+%s(%d) "%sspl%stests"
+%s(19) "fileobject_004.phpt"
+%s(%d) "%sspl%stests%sfileobject_004.phpt"
 ==DONE==
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt
diff -u php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt:1.1 
php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt:1.2
--- php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt:1.1 Thu Jun 12 
20:46:00 2008
+++ php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt     Tue Jul  8 
22:40:30 2008
@@ -18,16 +18,16 @@
 --EXPECTF--
 object(SplFileInfo)#2 (2) {
   [u"pathName":u"SplFileInfo":private]=>
-  %s(%d) "%sext%espl%etests"
-  [u"fileName":u"SplFileInfo":private]=>
   %s(%d) "%sext%espl%etests%efileobject_getfileinfo_basic.php"
+  [u"fileName":u"SplFileInfo":private]=>
+  %s(%d) "fileobject_getfileinfo_basic.php"
 }
 %s(%d) "%sext%espl%etests%efileobject_getfileinfo_basic.php"
 
 object(SplFileInfo)#4 (2) {
   [u"pathName":u"SplFileInfo":private]=>
-  %s(%d) "%sext%espl"
+  %s(%d) "%sext%espl%stests"
   [u"fileName":u"SplFileInfo":private]=>
-  %s(%d) "%sext%espl%etests"
+  %s(%d) "tests"
 }
 %s(%d) "%sext%espl%etests"

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to