]> granicus.if.org Git - php/commitdiff
SplFileObject::getFilename() should not overwrite SplFileInfo::getFilename()
authorHannes Magnusson <bjori@php.net>
Sun, 12 Nov 2006 17:08:45 +0000 (17:08 +0000)
committerHannes Magnusson <bjori@php.net>
Sun, 12 Nov 2006 17:08:45 +0000 (17:08 +0000)
(Fixes bug where SplFileObject::getFilename() returns relative/path/to/file)

ext/spl/spl_directory.c
ext/spl/tests/fileobject_003.phpt

index ec9ce07454473b78fcea1dd8c44e2c34f968d027..060ec68530d2cddc91515d23d6dc930beea4d5a7 100755 (executable)
@@ -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)
index 8bdb6036359a7ba0f159fd06a033ba7d9ca107d0..32ed8618d785a36d2f3f46dc49b1f44d5c2a0abc 100755 (executable)
@@ -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===