mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +02:00
add test for opendir, fix bugs found
This commit is contained in:
parent
0814b2df09
commit
72daaf1d44
2 changed files with 33 additions and 3 deletions
|
@ -51,7 +51,7 @@ PHAR_FUNC(phar_opendir) /* {{{ */
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
efree(entry);
|
efree(entry);
|
||||||
entry = filename;
|
entry = estrndup(filename, filename_len);
|
||||||
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
|
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
|
||||||
entry_len = filename_len;
|
entry_len = filename_len;
|
||||||
if (strstr(entry, "://")) {
|
if (strstr(entry, "://")) {
|
||||||
|
@ -70,11 +70,9 @@ PHAR_FUNC(phar_opendir) /* {{{ */
|
||||||
stream = php_stream_opendir(name, REPORT_ERRORS, context);
|
stream = php_stream_opendir(name, REPORT_ERRORS, context);
|
||||||
efree(name);
|
efree(name);
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
efree(entry);
|
|
||||||
goto skip_phar;
|
goto skip_phar;
|
||||||
}
|
}
|
||||||
php_stream_to_zval(stream, return_value);
|
php_stream_to_zval(stream, return_value);
|
||||||
efree(entry);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
ext/phar/tests/opendir.phpt
Normal file
32
ext/phar/tests/opendir.phpt
Normal 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===
|
Loading…
Add table
Add a link
Reference in a new issue