add test for opendir, fix bugs found

This commit is contained in:
Greg Beaver 2008-04-12 22:21:29 +00:00
parent 0814b2df09
commit 72daaf1d44
2 changed files with 33 additions and 3 deletions

View file

@ -51,7 +51,7 @@ PHAR_FUNC(phar_opendir) /* {{{ */
char *name;
efree(entry);
entry = filename;
entry = estrndup(filename, filename_len);
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
entry_len = filename_len;
if (strstr(entry, "://")) {
@ -70,11 +70,9 @@ PHAR_FUNC(phar_opendir) /* {{{ */
stream = php_stream_opendir(name, REPORT_ERRORS, context);
efree(name);
if (!stream) {
efree(entry);
goto skip_phar;
}
php_stream_to_zval(stream, return_value);
efree(entry);
return;
}
}

View file

@ -0,0 +1,32 @@
--TEST--
Phar: test opendir() interception
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip");?>
--INI--
phar.require_hash=1
phar.readonly=0
--FILE--
<?php
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$a = new Phar($fname);
$a['index.php'] = '<?php
$a = opendir("dir");
while (false !== ($e = readdir($a))) {
echo $e;
}
?>';
$a['dir/file1.txt'] = 'hi';
$a['dir/file2.txt'] = 'hi2';
$a['dir/file3.txt'] = 'hi3';
$a->setStub('<?php
Phar::interceptFileFuncs();
set_include_path("phar://" . __FILE__);
include "index.php";
__HALT_COMPILER();');
include $fname;
?>
===DONE===
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
--EXPECT--
file1.txtfile2.txtfile3.txt===DONE===