From 395d4ae5e3275fcfc4a4f1c39c8d4c27e5cc4b4d Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sat, 15 Jul 2006 13:01:44 +0000 Subject: [PATCH] - Fix issue with SplFileObject and directories --- ext/spl/spl_directory.c | 12 ++++++-- ext/spl/tests/fileobject_003.phpt | 48 +++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 1187610b1a..207d955930 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -205,9 +205,9 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0); intern->u.file.stream = php_stream_open_wrapper_ex(intern->file_name, intern->u.file.open_mode, (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, intern->u.file.context); - if (intern->u.file.stream == NULL) { + if (!intern->file_name_len || !intern->u.file.stream) { if (!EG(exception)) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot open file %s", intern->file_name); + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot open file '%s'", intern->file_name); } intern->file_name = NULL; /* until here it is not a copy */ intern->u.file.open_mode = NULL; @@ -218,6 +218,14 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu zend_list_addref(Z_RESVAL_P(intern->u.file.zcontext)); } + if (intern->file_name[intern->file_name_len-1] == '/' +#if defined(PHP_WIN32) || defined(NETWARE) + ||intern->file_name[intern->file_name_len-1] == '\\' +#endif + ) { + intern->file_name_len--; + } + intern->file_name = estrndup(intern->file_name, intern->file_name_len); intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len); diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt index f485357846..2624ff67a7 100755 --- a/ext/spl/tests/fileobject_003.phpt +++ b/ext/spl/tests/fileobject_003.phpt @@ -5,7 +5,7 @@ SPL: SplFileInfo cloning --FILE-- getPathname() == $c->getPathname()); + + $f = new SplFileObject($name); + var_dump($name); + var_dump($f->getPathName()); + $l = substr($f->getPathName(), -1); + var_dump($l != '/' && $l != '\\' && $l == $lc); + var_dump($f->getFileName()); + $l = substr($f->getFileName(), -1); + var_dump($l != '/' && $l != '\\' && $l == $lc); + var_dump($f->getPath()); + $l = substr($f->getPath(), -1); + var_dump($l != '/' && $l != '\\' && $l == $lp); } -test(dirname(__FILE__) . '/' . 'fileobject_001a.txt'); -test(dirname(__FILE__) . '/'); +test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', substr(dirname(__FILE__),-1)); +test(dirname(__FILE__) . '/', substr(dirname(__FILE__),-1), 'l'); +test(dirname(__FILE__), substr(dirname(__FILE__),-1), 'l'); ?> ===DONE=== @@ -36,6 +49,13 @@ object(SplFileInfo)#%d (0) { bool(false) bool(true) bool(true) +%s(%d) "%sfileobject_001a.txt" +string(%d) "%sfileobject_001a.txt" +bool(true) +string(%d) "%sfileobject_001a.txt" +bool(true) +string(%d) "%stests" +bool(true) ===1=== object(SplFileInfo)#%d (0) { } @@ -44,4 +64,26 @@ object(SplFileInfo)#%d (0) { bool(false) bool(true) bool(true) +%s(%d) "%stests/" +string(%d) "%stests" +bool(true) +string(%d) "%stests" +bool(true) +string(%d) "%sspl" +bool(true) +===2=== +object(SplFileInfo)#1 (0) { +} +object(SplFileInfo)#2 (0) { +} +bool(false) +bool(true) +bool(true) +%s(%d) "%stests" +string(%d) "%stests" +bool(true) +string(%d) "%stests" +bool(true) +string(%d) "%sspl" +bool(true) ===DONE=== -- 2.40.0