From: Pierre Joye Date: Wed, 12 Nov 2008 11:59:26 +0000 (+0000) Subject: - MFH: X-Git-Tag: php-5.2.7RC4~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36b9272e3cbeef53d903db1c57d54b4016ba0ad7;p=php - MFH: - #14962, makes extractTo 2nd argument really optional - replace ZEND_ENGINE_2_1 by PHP_ZIP_USE_OO - sync tests --- diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index e6fb77511e..0c7f5c7985 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -12,7 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Piere-Alain Joye | +----------------------------------------------------------------------+ */ @@ -473,7 +473,7 @@ static 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; @@ -493,7 +493,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; @@ -1137,7 +1137,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]) Create new zip using source uri for output, return TRUE on success or the error code */ static ZIPARCHIVE_METHOD(open) @@ -1975,7 +1975,7 @@ static ZIPARCHIVE_METHOD(extractTo) } 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_STRING: if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_files), Z_STRLEN_P(zval_files) TSRMLS_CC)) { diff --git a/ext/zip/php_zip.h b/ext/zip/php_zip.h index 9713408e64..8f6bac0e2d 100644 --- a/ext/zip/php_zip.h +++ b/ext/zip/php_zip.h @@ -32,10 +32,8 @@ extern zend_module_entry zip_module_entry; #define PHP_ZIP_VERSION_STRING "1.8.11" -#ifndef ZEND_ENGINE_2_1 -# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) || PHP_MAJOR_VERSION == 6 -# define ZEND_ENGINE_2_1 -# endif +#if ((PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6) +# define PHP_ZIP_USE_OO 1 #endif #ifndef Z_SET_REFCOUNT_P @@ -68,7 +66,7 @@ typedef struct _ze_zip_read_rsrc { struct zip_stat sb; } zip_read_rsrc; -#ifdef ZEND_ENGINE_2_1 +#ifdef PHP_ZIP_USE_OO #define ZIPARCHIVE_ME(name, arg_info, flags) ZEND_FENTRY(name, c_ziparchive_ ##name, arg_info, flags) #define ZIPARCHIVE_METHOD(name) ZEND_NAMED_FUNCTION(c_ziparchive_##name) diff --git a/ext/zip/tests/bug14962.phpt b/ext/zip/tests/bug14962.phpt new file mode 100644 index 0000000000..0006fd4b68 --- /dev/null +++ b/ext/zip/tests/bug14962.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #14962 (::extractTo second argument is not really optional) +--SKIPIF-- + +--FILE-- +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 diff --git a/ext/zip/tests/bug38943.inc b/ext/zip/tests/bug38943.inc new file mode 100644 index 0000000000..a6f45e8294 --- /dev/null +++ b/ext/zip/tests/bug38943.inc @@ -0,0 +1,16 @@ +testarray[] = 1; + var_dump($this->testarray); + } +} + +$z = new myZip; +$z->testp = "foobar"; +var_dump($z); + diff --git a/ext/zip/tests/bug38943.phpt b/ext/zip/tests/bug38943.phpt index d7236e314b..02985848dc 100644 --- a/ext/zip/tests/bug38943.phpt +++ b/ext/zip/tests/bug38943.phpt @@ -1,26 +1,14 @@ --TEST-- -#38943, properties in extended class cannot be set +#38943, properties in extended class cannot be set (< 5.3) --SKIPIF-- --FILE-- testarray[] = 1; - var_dump($this->testarray); - } -} - -$z = new myZip; -$z->testp = "foobar"; -var_dump($z); +include dirname(__FILE__) . '/bug38943.inc'; ?> --EXPECTF-- array(1) { diff --git a/ext/zip/tests/bug38943_2.phpt b/ext/zip/tests/bug38943_2.phpt new file mode 100644 index 0000000000..1aaba37c12 --- /dev/null +++ b/ext/zip/tests/bug38943_2.phpt @@ -0,0 +1,38 @@ +--TEST-- +#38943, properties in extended class cannot be set (5.3) +--SKIPIF-- + +--FILE-- + +--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) "" +} diff --git a/ext/zip/tests/bug7658.phpt b/ext/zip/tests/bug7658.phpt index 450c357239..56fd00fbab 100644 --- a/ext/zip/tests/bug7658.phpt +++ b/ext/zip/tests/bug7658.phpt @@ -7,6 +7,23 @@ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- 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); -@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 +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); +?> +--EXPECTF-- +array(0) { +} diff --git a/ext/zip/tests/oo_delete.phpt b/ext/zip/tests/oo_delete.phpt index 176cda44dc..9eac821734 100644 --- a/ext/zip/tests/oo_delete.phpt +++ b/ext/zip/tests/oo_delete.phpt @@ -63,7 +63,12 @@ $sb = $zip->statIndex(1); var_dump($sb); $sb = $zip->statIndex(2); var_dump($sb); -@unlink($file); +$zip->close(); +unset($zip); + +if (file_exists($file)) { + unlink($file); +} ?> --EXPECTF-- ok