mirror of
https://github.com/php/php-src.git
synced 2025-08-21 01:45:16 +02:00
- fix #14962 (makes 2nd argument really optional)
- replace ZEND_ENGINE_2_1 test with PHP_ZIP_USE_OO, version independent - sync tests with 5.3
This commit is contained in:
parent
3f12e9e699
commit
f5553f3494
8 changed files with 146 additions and 72 deletions
|
@ -135,7 +135,7 @@ static char * php_zip_make_relative_path(char *path, int path_len) /* {{{ */
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
#ifdef ZEND_ENGINE_2_1
|
||||
#ifdef PHP_ZIP_USE_OO
|
||||
/* {{{ php_zip_extract_file */
|
||||
static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len TSRMLS_DC)
|
||||
{
|
||||
|
@ -740,7 +740,7 @@ static const zend_function_entry zip_functions[] = {
|
|||
/* }}} */
|
||||
|
||||
/* {{{ ZE2 OO definitions */
|
||||
#ifdef ZEND_ENGINE_2_1
|
||||
#ifdef PHP_ZIP_USE_OO
|
||||
static zend_class_entry *zip_class_entry;
|
||||
static zend_object_handlers zip_object_handlers;
|
||||
|
||||
|
@ -760,7 +760,7 @@ typedef struct _zip_prop_handler {
|
|||
#endif
|
||||
/* }}} */
|
||||
|
||||
#ifdef ZEND_ENGINE_2_1
|
||||
#ifdef PHP_ZIP_USE_OO
|
||||
static void php_zip_register_prop_handler(HashTable *prop_handler, char *name, zip_read_int_t read_int_func, zip_read_const_char_t read_char_func, zip_read_const_char_from_ze_t read_char_from_obj_func, int rettype TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
zip_prop_handler hnd;
|
||||
|
@ -1423,7 +1423,7 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
#ifdef ZEND_ENGINE_2_1
|
||||
#ifdef PHP_ZIP_USE_OO
|
||||
/* {{{ proto mixed ZipArchive::open(string source [, int flags]) U
|
||||
Create new zip using source uri for output, return TRUE on success or the error code */
|
||||
static ZIPARCHIVE_METHOD(open)
|
||||
|
@ -2413,15 +2413,15 @@ static ZIPARCHIVE_METHOD(extractTo)
|
|||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (php_stream_stat_path(pathto, &ssb) < 0) {
|
||||
ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
|
||||
if (!ret) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
if (php_stream_stat_path(pathto, &ssb) < 0) {
|
||||
ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
|
||||
if (!ret) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
ZIP_FROM_OBJECT(intern, this);
|
||||
if (zval_files) {
|
||||
if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) {
|
||||
switch (Z_TYPE_P(zval_files)) {
|
||||
case IS_UNICODE:
|
||||
if (FAILURE == php_stream_path_param_encode(&zval_files, &file, &file_len, REPORT_ERRORS, FG(default_context))) {
|
||||
|
@ -2443,6 +2443,7 @@ static ZIPARCHIVE_METHOD(extractTo)
|
|||
RETURN_FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case IS_ARRAY:
|
||||
nelems = zend_hash_num_elements(Z_ARRVAL_P(zval_files));
|
||||
if (nelems == 0 ) {
|
||||
|
@ -2476,7 +2477,7 @@ static ZIPARCHIVE_METHOD(extractTo)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case IS_LONG:
|
||||
|
||||
default:
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument, expect string or array of strings");
|
||||
break;
|
||||
|
@ -2659,7 +2660,7 @@ static const zend_function_entry zip_class_functions[] = {
|
|||
/* {{{ PHP_MINIT_FUNCTION */
|
||||
static PHP_MINIT_FUNCTION(zip)
|
||||
{
|
||||
#ifdef ZEND_ENGINE_2_1
|
||||
#ifdef PHP_ZIP_USE_OO
|
||||
zend_class_entry ce;
|
||||
|
||||
memcpy(&zip_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||
|
@ -2742,7 +2743,7 @@ static PHP_MINIT_FUNCTION(zip)
|
|||
*/
|
||||
static PHP_MSHUTDOWN_FUNCTION(zip)
|
||||
{
|
||||
#ifdef ZEND_ENGINE_2_1
|
||||
#ifdef PHP_ZIP_USE_OO
|
||||
zend_hash_destroy(&zip_prop_handlers);
|
||||
php_unregister_url_stream_wrapper("zip" TSRMLS_CC);
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,10 @@ extern zend_module_entry zip_module_entry;
|
|||
#endif
|
||||
/* }}} */
|
||||
|
||||
#if ((PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6)
|
||||
# define PHP_ZIP_USE_OO 1
|
||||
#endif
|
||||
|
||||
typedef struct _ze_zip_rsrc {
|
||||
struct zip *za;
|
||||
int index_current;
|
||||
|
|
34
ext/zip/tests/bug14962.phpt
Normal file
34
ext/zip/tests/bug14962.phpt
Normal file
|
@ -0,0 +1,34 @@
|
|||
--TEST--
|
||||
Bug #14962 (::extractTo second argument is not really optional)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
/* $Id$ */
|
||||
if(!extension_loaded('zip')) die('skip');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$dir = dirname(__FILE__);
|
||||
$file = '__tmp14962.txt';
|
||||
$fullpath = $dir . '/' . $file;
|
||||
$za = new ZipArchive;
|
||||
$za->open($dir . '/__14962.zip', ZIPARCHIVE::CREATE);
|
||||
$za->addFromString($file, '1234');
|
||||
$za->close();
|
||||
|
||||
if (!is_file($dir . "/__14962.zip")) {
|
||||
die('failed to create the archive');
|
||||
}
|
||||
$za = new ZipArchive;
|
||||
$za->open($dir . '/__14962.zip');
|
||||
$za->extractTo($dir, NULL);
|
||||
$za->close();
|
||||
|
||||
if (is_file($fullpath)) {
|
||||
unlink($fullpath);
|
||||
echo "Ok";
|
||||
}
|
||||
unlink($dir . '/' . '__14962.zip');
|
||||
?>
|
||||
--EXPECT--
|
||||
Ok
|
16
ext/zip/tests/bug38943.inc
Normal file
16
ext/zip/tests/bug38943.inc
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
class myZip extends ZipArchive {
|
||||
private $test = 0;
|
||||
public $testp = 1;
|
||||
private $testarray = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->testarray[] = 1;
|
||||
var_dump($this->testarray);
|
||||
}
|
||||
}
|
||||
|
||||
$z = new myZip;
|
||||
$z->testp = "foobar";
|
||||
var_dump($z);
|
||||
|
|
@ -7,20 +7,7 @@ if(!extension_loaded('zip')) die('skip');
|
|||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
class myZip extends ZipArchive {
|
||||
private $test = 0;
|
||||
public $testp = 1;
|
||||
private $testarray = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->testarray[] = 1;
|
||||
var_dump($this->testarray);
|
||||
}
|
||||
}
|
||||
|
||||
$z = new myZip;
|
||||
$z->testp = "foobar";
|
||||
var_dump($z);
|
||||
include dirname(__FILE__) . '/bug38943.inc';
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(1) {
|
||||
|
@ -37,14 +24,14 @@ object(myZip)#1 (8) {
|
|||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
[u"status"]=>
|
||||
["status"]=>
|
||||
int(0)
|
||||
[u"statusSys"]=>
|
||||
["statusSys"]=>
|
||||
int(0)
|
||||
[u"numFiles"]=>
|
||||
["numFiles"]=>
|
||||
int(0)
|
||||
[u"filename"]=>
|
||||
["filename"]=>
|
||||
string(0) ""
|
||||
[u"comment"]=>
|
||||
["comment"]=>
|
||||
string(0) ""
|
||||
}
|
||||
|
|
38
ext/zip/tests/bug38943_2.phpt
Normal file
38
ext/zip/tests/bug38943_2.phpt
Normal file
|
@ -0,0 +1,38 @@
|
|||
--TEST--
|
||||
#38943, properties in extended class cannot be set (5.3)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
/* $Id$ */
|
||||
if(!extension_loaded('zip')) die('skip');
|
||||
if (!defined('PHP_VERSION_MAJOR')) die('skip test for5.3+ only');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'bug38943.inc';
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
object(myZip)#1 (%d) {
|
||||
["test":"myZip":private]=>
|
||||
int(0)
|
||||
["testp"]=>
|
||||
string(6) "foobar"
|
||||
["testarray":"myZip":private]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
["status"]=>
|
||||
int(0)
|
||||
["statusSys"]=>
|
||||
int(0)
|
||||
["numFiles"]=>
|
||||
int(0)
|
||||
["filename"]=>
|
||||
string(0) ""
|
||||
["comment"]=>
|
||||
string(0) ""
|
||||
}
|
|
@ -26,15 +26,15 @@ int(0)
|
|||
string(0) ""
|
||||
string(0) ""
|
||||
object(ZipArchive)#1 (5) {
|
||||
[u"status"]=>
|
||||
["status"]=>
|
||||
int(0)
|
||||
[u"statusSys"]=>
|
||||
["statusSys"]=>
|
||||
int(0)
|
||||
[u"numFiles"]=>
|
||||
["numFiles"]=>
|
||||
int(0)
|
||||
[u"filename"]=>
|
||||
["filename"]=>
|
||||
string(0) ""
|
||||
[u"comment"]=>
|
||||
["comment"]=>
|
||||
string(0) ""
|
||||
}
|
||||
Done
|
||||
|
|
|
@ -7,6 +7,23 @@ if(!extension_loaded('zip')) die('skip');
|
|||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$expect = array(
|
||||
"mimetype",
|
||||
"Configurations2/statusbar/",
|
||||
"Configurations2/accelerator/current.xml",
|
||||
"Configurations2/floater/",
|
||||
"Configurations2/popupmenu/",
|
||||
"Configurations2/progressbar/",
|
||||
"Configurations2/menubar/",
|
||||
"Configurations2/toolbar/",
|
||||
"Configurations2/images/Bitmaps/",
|
||||
"content.xml",
|
||||
"styles.xml",
|
||||
"meta.xml",
|
||||
"Thumbnails/thumbnail.png",
|
||||
"settings.xml",
|
||||
"META-INF/manifest.xml",
|
||||
);
|
||||
$dirname = dirname(__FILE__) . '/';
|
||||
include $dirname . 'utils.inc';
|
||||
$file = $dirname . '__tmp_bug7658.odt';
|
||||
|
@ -16,46 +33,23 @@ if(!$zip->open($file)) {
|
|||
echo 'failed';
|
||||
}
|
||||
|
||||
dump_entries_name($zip);
|
||||
|
||||
$zip->deleteName('content.xml');
|
||||
$zip->addFile($dirname . "bug7658.xml","content.xml");
|
||||
$zip->close();
|
||||
echo "\n";
|
||||
$zip->open($file);
|
||||
dump_entries_name($zip);
|
||||
|
||||
for($i=0; $i < $zip->numFiles; $i++) {
|
||||
$sb = $zip->statIndex($i);
|
||||
$found[] = $sb['name'];
|
||||
}
|
||||
$ar = array_diff($found, $expect);
|
||||
|
||||
var_dump($ar);
|
||||
unset($zip);
|
||||
unlink($file);
|
||||
?>
|
||||
--EXPECT--
|
||||
0 mimetype
|
||||
1 Configurations2/statusbar/
|
||||
2 Configurations2/accelerator/current.xml
|
||||
3 Configurations2/floater/
|
||||
4 Configurations2/popupmenu/
|
||||
5 Configurations2/progressbar/
|
||||
6 Configurations2/menubar/
|
||||
7 Configurations2/toolbar/
|
||||
8 Configurations2/images/Bitmaps/
|
||||
9 content.xml
|
||||
10 styles.xml
|
||||
11 meta.xml
|
||||
12 Thumbnails/thumbnail.png
|
||||
13 settings.xml
|
||||
14 META-INF/manifest.xml
|
||||
|
||||
0 mimetype
|
||||
1 Configurations2/statusbar/
|
||||
2 Configurations2/accelerator/current.xml
|
||||
3 Configurations2/floater/
|
||||
4 Configurations2/popupmenu/
|
||||
5 Configurations2/progressbar/
|
||||
6 Configurations2/menubar/
|
||||
7 Configurations2/toolbar/
|
||||
8 Configurations2/images/Bitmaps/
|
||||
9 styles.xml
|
||||
10 meta.xml
|
||||
11 Thumbnails/thumbnail.png
|
||||
12 settings.xml
|
||||
13 META-INF/manifest.xml
|
||||
14 content.xml
|
||||
--EXPECTF--
|
||||
array(0) {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue