com php-src: Fix bug 61671 ext\spl\tests\fileobject_0 03.phpt fails: ext/spl/spl_directory.c ext/sp l/tests/SplFileObject_fflush_basic_001.phpt ext
/spl/tests/SplFileObject_ftruncate_error_001.phpt ext/spl/tests/fileobject_003.phpt
| From: | Anatoliy Belsky | Date: | Thu, 19 Apr 2012 09:20:16 +0000 |
| Subject: | com php-src: Fix bug 61671 ext\spl\tests\fileobject_0 03.phpt fails: ext/spl/spl_directory.c ext/sp l/tests/SplFileObject_fflush_basic_001.phpt ext /spl/tests/SplFileObject_ftruncate_error_001.phpt ext/spl/tests/fileobject_003.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-68823@lists.php.net to get a copy of this message | ||
Commit: adfb4c62b76ef241978814e10cae70498f52ea29
Author: Anatoliy Belsky <ab@php.net> Thu, 19 Apr 2012 11:20:16 +0200
Parents: 4650b2164b641ba3fd9d733e8cc82e386aa98772
Branches: PHP-5.3 PHP-5.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=adfb4c62b76ef241978814e10cae70498f52ea29
Log:
Fix bug 61671 ext\spl\tests\fileobject_003.phpt fails
The solution was already introduced in 5..4 by Etienne Kneuss and
Pierre but wasn't merged back into 5.3 . SplFileObject should
not be used with directories. So just putting together all the
necessary pieces from 5.4
Bugs:
https://bugs.php.net/61671
Changed paths:
M ext/spl/spl_directory.c
M ext/spl/tests/SplFileObject_fflush_basic_001.phpt
M ext/spl/tests/SplFileObject_ftruncate_error_001.phpt
M ext/spl/tests/fileobject_003.phpt
Diff:
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 04da4e6..aaa256d 100755
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -271,7 +271,18 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path
TS
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 FAILURE;
+ }
+
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) | ENFORCE_SAFE_MODE | REPORT_ERRORS,
NULL, intern->u.file.context);
diff --git a/ext/spl/tests/SplFileObject_fflush_basic_001.phpt
b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt
index baab156..2d8a9c8 100644
--- a/ext/spl/tests/SplFileObject_fflush_basic_001.phpt
+++ b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt
@@ -17,9 +17,12 @@ class VariableStream {
var $varname;
function stream_open($path, $mode, $options, &$opened_path)
- {
+ {
return true;
}
+
+ function url_stat() {
+ }
}
stream_wrapper_register("SPLtest", "VariableStream");
$ftruncate_test = "";
diff --git a/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt
b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt
index 90b27ec..a2eef60 100644
--- a/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt
+++ b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt
@@ -12,6 +12,9 @@ class VariableStream {
{
return true;
}
+
+ function url_stat() {
+ }
}
stream_wrapper_register("SPLtest", "VariableStream");
$ftruncate_test = "";
diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt
index 6679673..6cc650b 100755
--- a/ext/spl/tests/fileobject_003.phpt
+++ b/ext/spl/tests/fileobject_003.phpt
@@ -18,20 +18,27 @@ function test($name, $lc, $lp)
var_dump($o == $c);
var_dump($o->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);
-
- $fo = $o->openFile();
- var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath());
+ try {
+ $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);
+ } catch (LogicException $e) {
+ echo "LogicException: ".$e->getMessage()."\n";
+ }
+ 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));
@@ -84,16 +91,8 @@ object(SplFileInfo)#%d (2) {
bool(false)
bool(true)
bool(true)
-%s(%d) "%stests/"
-string(%d) "%stests"
-bool(true)
-string(5) "tests"
-bool(true)
-string(%d) "%sspl"
-bool(true)
-string(%d) "%stests"
-string(%d) "tests"
-string(%d) "%sspl"
+LogicException: Cannot use SplFileObject with directories
+LogicException: Cannot use SplFileObject with directories
===2===
object(SplFileInfo)#%d (2) {
["pathName":"SplFileInfo":private]=>
@@ -110,14 +109,6 @@ object(SplFileInfo)#%d (2) {
bool(false)
bool(true)
bool(true)
-%s(%d) "%stests"
-string(%d) "%stests"
-bool(true)
-string(%d) "tests"
-bool(true)
-string(%d) "%sspl"
-bool(true)
-string(%d) "%stests"
-string(5) "tests"
-string(%d) "%sspl"
+LogicException: Cannot use SplFileObject with directories
+LogicException: Cannot use SplFileObject with directories
===DONE===