From: Etienne Kneuss Date: Tue, 8 Jul 2008 22:40:48 +0000 (+0000) Subject: MFH: - Fix filename in debug_info X-Git-Tag: php-5.3.0alpha1~430 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=767eaa7a4ec2d264386c8154463f49f49961f10c;p=php MFH: - Fix filename in debug_info - Fix #45345 (getPathInfo on the file instead of the dir) - Remove trailing / on input --- diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 9bd06e82ef..4ae4babdf1 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -347,17 +347,23 @@ void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, intern->file_name = use_copy ? estrndup(path, len) : path; intern->file_name_len = len; - p1 = strrchr(path, '/'); + while(IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) { + intern->file_name[intern->file_name_len-1] = 0; + intern->file_name_len--; + } + + p1 = strrchr(intern->file_name, '/'); #if defined(PHP_WIN32) || defined(NETWARE) - p2 = strrchr(path, '\\'); + p2 = strrchr(intern->file_name, '\\'); #else p2 = 0; #endif if (p1 || p2) { - intern->_path_len = (p1 > p2 ? p1 : p2) - path; + intern->_path_len = (p1 > p2 ? p1 : p2) - intern->file_name; } else { intern->_path_len = 0; } + intern->_path = estrndup(path, intern->_path_len); } /* }}} */ @@ -499,7 +505,25 @@ static int spl_filesystem_is_invalid_or_dot(const char * d_name) /* {{{ */ } /* }}} */ -static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{{ */ +static char *spl_filesystem_object_get_pathname(spl_filesystem_object *intern, int *len TSRMLS_DC) { /* {{{ */ + switch (intern->type) { + case SPL_FS_INFO: + case SPL_FS_FILE: + *len = intern->file_name_len; + 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; + return intern->file_name; + } + } + *len = 0; + return NULL; +} +/* }}} */ + +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); HashTable *rv; @@ -518,13 +542,20 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T 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 TSRMLS_CC); pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1, &pnlen TSRMLS_CC); + path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, path, path_len, 1); efree(pnstr); + if (intern->file_name) { pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1, &pnlen TSRMLS_CC); - add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name, intern->file_name_len, 1); + spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); + + if (path_len && path_len < intern->file_name_len) { + add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1); + } else { + add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name, intern->file_name_len, 1); + } efree(pnstr); } if (intern->type == SPL_FS_DIR) { @@ -560,7 +591,7 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T return rv; } -/* }}}} */ +/* }}} */ #define DIT_CTOR_FLAGS 0x00000001 #define DIT_CTOR_GLOB 0x00000002 @@ -775,18 +806,14 @@ SPL_METHOD(DirectoryIterator, getBasename) SPL_METHOD(SplFileInfo, getPathname) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - switch (intern->type) { - case SPL_FS_INFO: - case SPL_FS_FILE: - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - case SPL_FS_DIR: - if (intern->u.dir.entry.d_name[0]) { - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } + char *path; + int path_len; + path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); + if (path != NULL) { + RETURN_STRINGL(path, path_len, 1); + } else { + RETURN_FALSE; } - RETURN_BOOL(0); } /* }}} */ @@ -1092,8 +1119,10 @@ SPL_METHOD(SplFileInfo, getPathInfo) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { int path_len; - char *path = spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); - spl_filesystem_object_create_info(intern, path, path_len, 1, ce, return_value TSRMLS_CC); + char *path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); + if (path) { + spl_filesystem_object_create_info(intern, path, path_len, 1, ce, return_value TSRMLS_CC); + } } php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); diff --git a/ext/spl/tests/dit_001.phpt b/ext/spl/tests/dit_001.phpt index 00918dc9b5..2a30608cc8 100755 --- a/ext/spl/tests/dit_001.phpt +++ b/ext/spl/tests/dit_001.phpt @@ -10,9 +10,11 @@ var_dump(is_string($d)); ?> ===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]=> diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt index 96fb9b4544..6679673700 100755 --- a/ext/spl/tests/fileobject_003.phpt +++ b/ext/spl/tests/fileobject_003.phpt @@ -47,13 +47,13 @@ object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> string(%d) "%s" ["fileName":"SplFileInfo":private]=> - string(%d) "%sfileobject_001a.txt" + string(%d) "fileobject_001a.txt" } object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> string(%d) "%s" ["fileName":"SplFileInfo":private]=> - string(%d) "%sfileobject_001a.txt" + string(%d) "fileobject_001a.txt" } bool(false) bool(true) @@ -92,8 +92,8 @@ bool(true) string(%d) "%sspl" bool(true) string(%d) "%stests" -string(%d) "%stests" -string(%d) "%stests" +string(%d) "tests" +string(%d) "%sspl" ===2=== object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> diff --git a/ext/spl/tests/fileobject_getfileinfo_basic.phpt b/ext/spl/tests/fileobject_getfileinfo_basic.phpt index b0d82ad31e..97d0de2459 100644 --- a/ext/spl/tests/fileobject_getfileinfo_basic.phpt +++ b/ext/spl/tests/fileobject_getfileinfo_basic.phpt @@ -14,20 +14,31 @@ var_dump($fi = $s->getFileInfo(), (string)$fi); $d = new SplFileInfo( __DIR__ ); echo "\n"; var_dump($fi = $d->getFileInfo(), (string)$fi); +$d = new SplFileInfo( __DIR__."/" ); +echo "\n"; +var_dump($fi = $d->getFileInfo(), (string)$fi); ?> --EXPECTF-- -object(SplFileInfo)#2 (2) { +object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> - string(%d) "%sext%espl%etests" - ["fileName":"SplFileInfo":private]=> string(%d) "%sext%espl%etests%efileobject_getfileinfo_basic.php" + ["fileName":"SplFileInfo":private]=> + string(%d) "fileobject_getfileinfo_basic.php" } string(%d) "%sext%espl%etests%efileobject_getfileinfo_basic.php" -object(SplFileInfo)#4 (2) { +object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> - string(%d) "%sext%espl" + string(%d) "%sext%espl%etests" ["fileName":"SplFileInfo":private]=> + string(%d) "tests" +} +string(%d) "%sext%espl%etests" + +object(SplFileInfo)#%d (2) { + ["pathName":"SplFileInfo":private]=> string(%d) "%sext%espl%etests" + ["fileName":"SplFileInfo":private]=> + string(%d) "tests" } string(%d) "%sext%espl%etests"