pajoye                                   Thu, 08 Sep 2011 23:07:48 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=316433

Log:
- improve r316420 (SplFileObject cannot and should not accept directories)

Changed paths:
    U   php/php-src/branches/PHP_5_4/ext/spl/spl_directory.c
    U   php/php-src/branches/PHP_5_4/ext/spl/tests/fileobject_003.phpt
    U   php/php-src/trunk/ext/spl/spl_directory.c
    U   php/php-src/trunk/ext/spl/tests/fileobject_003.phpt

Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_directory.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/spl_directory.c        2011-09-08 
22:05:33 UTC (rev 316432)
+++ php/php-src/branches/PHP_5_4/ext/spl/spl_directory.c        2011-09-08 
23:07:48 UTC (rev 316433)
@@ -251,7 +251,18 @@

 static int spl_filesystem_file_open(spl_filesystem_object *intern, int 
use_include_path, int silent TSRMLS_DC) /* {{{ */
 {
+       zval  tmp;
+
        intern->type = SPL_FS_FILE;
+
+       php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp 
TSRMLS_CC);
+       if (Z_LVAL(tmp)) {
+               intern->u.file.open_mode = NULL;
+               intern->file_name = NULL;
+               zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, 
"Cannot use SplFileObject with directories");
+               return;
+       }
+
        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);

@@ -2254,7 +2265,7 @@
                zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, 
"Cannot use SplFileObject with directories");
                return;
        }
-
+
        if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == 
SUCCESS) {
                tmp_path_len = strlen(intern->u.file.stream->orig_path);


Modified: php/php-src/branches/PHP_5_4/ext/spl/tests/fileobject_003.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/tests/fileobject_003.phpt      
2011-09-08 22:05:33 UTC (rev 316432)
+++ php/php-src/branches/PHP_5_4/ext/spl/tests/fileobject_003.phpt      
2011-09-08 23:07:48 UTC (rev 316433)
@@ -33,8 +33,12 @@
        } catch (LogicException $e) {
                echo "LogicException: ".$e->getMessage()."\n";
        }
-       $fo = $o->openFile();
-       var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath());
+       try {
+               $fo = $o->openFile();
+               var_dump($fo->getPathName(), $fo->getFileName(), 
$fo->getPath());
+       } catch (LogicException $e) {
+               echo "LogicException: ".$e->getMessage()."\n";
+       }
 }

 test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', 
substr(dirname(__FILE__),-1));
@@ -88,9 +92,7 @@
 bool(true)
 bool(true)
 LogicException: Cannot use SplFileObject with directories
-string(%d) "%stests"
-string(%d) "tests"
-string(%d) "%sspl"
+LogicException: Cannot use SplFileObject with directories
 ===2===
 object(SplFileInfo)#%d (2) {
   ["pathName":"SplFileInfo":private]=>
@@ -108,7 +110,5 @@
 bool(true)
 bool(true)
 LogicException: Cannot use SplFileObject with directories
-string(%d) "%stests"
-string(5) "tests"
-string(%d) "%sspl"
+LogicException: Cannot use SplFileObject with directories
 ===DONE===

Modified: php/php-src/trunk/ext/spl/spl_directory.c
===================================================================
--- php/php-src/trunk/ext/spl/spl_directory.c   2011-09-08 22:05:33 UTC (rev 
316432)
+++ php/php-src/trunk/ext/spl/spl_directory.c   2011-09-08 23:07:48 UTC (rev 
316433)
@@ -251,7 +251,18 @@

 static int spl_filesystem_file_open(spl_filesystem_object *intern, int 
use_include_path, int silent TSRMLS_DC) /* {{{ */
 {
+       zval  tmp;
+
        intern->type = SPL_FS_FILE;
+
+       php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp 
TSRMLS_CC);
+       if (Z_LVAL(tmp)) {
+               intern->u.file.open_mode = NULL;
+               intern->file_name = NULL;
+               zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, 
"Cannot use SplFileObject with directories");
+               return;
+       }
+
        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);

@@ -2255,7 +2266,7 @@
                zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, 
"Cannot use SplFileObject with directories");
                return;
        }
-
+
        if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == 
SUCCESS) {
                tmp_path_len = strlen(intern->u.file.stream->orig_path);


Modified: php/php-src/trunk/ext/spl/tests/fileobject_003.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/fileobject_003.phpt 2011-09-08 22:05:33 UTC 
(rev 316432)
+++ php/php-src/trunk/ext/spl/tests/fileobject_003.phpt 2011-09-08 23:07:48 UTC 
(rev 316433)
@@ -33,8 +33,12 @@
        } catch (LogicException $e) {
                echo "LogicException: ".$e->getMessage()."\n";
        }
-       $fo = $o->openFile();
-       var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath());
+       try {
+               $fo = $o->openFile();
+               var_dump($fo->getPathName(), $fo->getFileName(), 
$fo->getPath());
+       } catch (LogicException $e) {
+               echo "LogicException: ".$e->getMessage()."\n";
+       }
 }

 test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', 
substr(dirname(__FILE__),-1));
@@ -88,9 +92,7 @@
 bool(true)
 bool(true)
 LogicException: Cannot use SplFileObject with directories
-string(%d) "%stests"
-string(%d) "tests"
-string(%d) "%sspl"
+LogicException: Cannot use SplFileObject with directories
 ===2===
 object(SplFileInfo)#%d (2) {
   ["pathName":"SplFileInfo":private]=>
@@ -108,7 +110,5 @@
 bool(true)
 bool(true)
 LogicException: Cannot use SplFileObject with directories
-string(%d) "%stests"
-string(5) "tests"
-string(%d) "%sspl"
+LogicException: Cannot use SplFileObject with directories
 ===DONE===

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

Reply via email to