From: Hannes Magnusson Date: Sun, 12 Nov 2006 17:08:45 +0000 (+0000) Subject: SplFileObject::getFilename() should not overwrite SplFileInfo::getFilename() X-Git-Tag: RELEASE_1_0_0RC1~1046 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d98dfdb1196e82d484ae9172f67b2bfdf76e1d79;p=php SplFileObject::getFilename() should not overwrite SplFileInfo::getFilename() (Fixes bug where SplFileObject::getFilename() returns relative/path/to/file) --- diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index ec9ce07454..060ec68530 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -550,7 +550,7 @@ SPL_METHOD(SplFileInfo, getFilename) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - if (intern->path_len) { + if (intern->path_len && intern->path_len < intern->file_name_len) { RETURN_STRINGL(intern->file_name + intern->path_len + 1, intern->file_name_len - (intern->path_len + 1), 1); } else { RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); @@ -1654,15 +1654,6 @@ SPL_METHOD(SplFileObject, rewind) spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC); } /* }}} */ -/* {{{ proto string SplFileObject::getFilename() - Return the filename */ -SPL_METHOD(SplFileObject, getFilename) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); -} /* }}} */ - /* {{{ proto void SplFileObject::eof() Return whether end of file is reached */ SPL_METHOD(SplFileObject, eof) @@ -2140,7 +2131,6 @@ ZEND_END_ARG_INFO() static zend_function_entry spl_SplFileObject_functions[] = { SPL_ME(SplFileObject, __construct, arginfo_file_object___construct, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, getFilename, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, rewind, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, eof, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, valid, NULL, ZEND_ACC_PUBLIC) diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt index 8bdb603635..32ed8618d7 100755 --- a/ext/spl/tests/fileobject_003.phpt +++ b/ext/spl/tests/fileobject_003.phpt @@ -55,12 +55,12 @@ bool(true) %s(%d) "%sfileobject_001a.txt" string(%d) "%sfileobject_001a.txt" bool(true) -string(%d) "%sfileobject_001a.txt" +string(19) "fileobject_001a.txt" bool(true) string(%d) "%stests" bool(true) string(%d) "%sfileobject_001a.txt" -string(%d) "%sfileobject_001a.txt" +string(19) "fileobject_001a.txt" string(%d) "%stests" ===1=== object(SplFileInfo)#%d (0) { @@ -73,7 +73,7 @@ bool(true) %s(%d) "%stests/" string(%d) "%stests" bool(true) -string(%d) "%stests" +string(5) "tests" bool(true) string(%d) "%sspl" bool(true) @@ -91,11 +91,11 @@ bool(true) %s(%d) "%stests" string(%d) "%stests" bool(true) -string(%d) "%stests" +string(%d) "tests" bool(true) string(%d) "%sspl" bool(true) string(%d) "%stests" -string(%d) "%stests" +string(5) "tests" string(%d) "%sspl" ===DONE===