diff options
-rw-r--r-- | php-pecl-zip.spec | 6 | ||||
-rw-r--r-- | zip-php8.patch | 775 |
2 files changed, 704 insertions, 77 deletions
diff --git a/php-pecl-zip.spec b/php-pecl-zip.spec index a2dd1ed..e089347 100644 --- a/php-pecl-zip.spec +++ b/php-pecl-zip.spec @@ -35,13 +35,14 @@ Summary: A ZIP archive management extension Summary(fr): Une extension de gestion des ZIP Name: %{?scl_prefix}php-pecl-zip Version: %{upstream_version}%{?upstream_prever:~%{upstream_lower}} -Release: 4%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +Release: 5%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} License: PHP Group: Development/Languages URL: https://pecl.php.net/package/zip Source0: https://pecl.php.net/get/%{pecl_name}-%{upstream_version}%{?upstream_prever}.tgz +# diff from previous tag for php8 and tests directories Patch0: %{pecl_name}-php8.patch BuildRequires: %{?dtsprefix}gcc @@ -271,6 +272,9 @@ fi #### TODO: SCLs on EL-8 still use libzip from default stream (7.2 => 1.5.1) %changelog +* Mon Aug 17 2020 Remi Collet <remi@remirepo.net> - 1.19.0-5 +- rebuild for 8.0.0beta2 + * Wed Aug 5 2020 Remi Collet <remi@remirepo.net> - 1.19.0-4 - rebuild for 8.0.0beta1 diff --git a/zip-php8.patch b/zip-php8.patch index 95b4e4c..6d14487 100644 --- a/zip-php8.patch +++ b/zip-php8.patch @@ -1,8 +1,25 @@ diff --git a/php8/php_zip.c b/php8/php_zip.c -index f131966..841488b 100644 +index f131966..43c2da9 100644 --- a/php8/php_zip.c +++ b/php8/php_zip.c -@@ -334,7 +334,7 @@ typedef struct { +@@ -52,11 +52,12 @@ static int le_zip_entry; + } + /* }}} */ + +-/* {{{ PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) */ ++/* {{{ PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) ++ This is always used for the first argument*/ + #define PHP_ZIP_STAT_PATH(za, path, path_len, flags, sb) \ +- if (path_len < 1) { \ +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); \ +- RETURN_FALSE; \ ++ if (path_len == 0) { \ ++ zend_argument_value_error(1, "cannot be empty"); \ ++ RETURN_THROWS(); \ + } \ + if (zip_stat(za, path, flags, &sb) != 0) { \ + RETURN_FALSE; \ +@@ -334,7 +335,7 @@ typedef struct { #endif } zip_options; @@ -11,21 +28,33 @@ index f131966..841488b 100644 /* {{{ */ { zval *option; -@@ -347,23 +347,23 @@ static int php_zip_parse_options(zval *options, zip_options *opts) +@@ -347,25 +348,42 @@ static int php_zip_parse_options(zval *options, zip_options *opts) opts->enc_method = -1; /* -1 to not change default */ #endif - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) { ++ if (Z_TYPE_P(option) != IS_FALSE && Z_TYPE_P(option) != IS_TRUE) { ++ php_error_docref(NULL, E_WARNING, "Option \"remove_all_path\" must be of type bool, %s given", ++ zend_zval_type_name(option)); ++ } opts->remove_all_path = zval_get_long(option); } - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "comp_method", sizeof("comp_method") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "comp_method", sizeof("comp_method") - 1)) != NULL) { ++ if (Z_TYPE_P(option) != IS_LONG) { ++ php_error_docref(NULL, E_WARNING, "Option \"comp_method\" must be of type int, %s given", ++ zend_zval_type_name(option)); ++ } opts->comp_method = zval_get_long(option); - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "comp_flags", sizeof("comp_flags") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "comp_flags", sizeof("comp_flags") - 1)) != NULL) { ++ if (Z_TYPE_P(option) != IS_LONG) { ++ php_error_docref(NULL, E_WARNING, "Option \"comp_flags\" must be of type int, %s given", ++ zend_zval_type_name(option)); ++ } opts->comp_flags = zval_get_long(option); } } @@ -33,41 +62,95 @@ index f131966..841488b 100644 #ifdef HAVE_ENCRYPTION - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "enc_method", sizeof("enc_method") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "enc_method", sizeof("enc_method") - 1)) != NULL) { ++ if (Z_TYPE_P(option) != IS_LONG) { ++ php_error_docref(NULL, E_WARNING, "Option \"enc_method\" must be of type int, %s given", ++ zend_zval_type_name(option)); ++ } opts->enc_method = zval_get_long(option); - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "enc_password", sizeof("enc_password") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "enc_password", sizeof("enc_password") - 1)) != NULL) { if (Z_TYPE_P(option) != IS_STRING) { - php_error_docref(NULL, E_WARNING, "enc_password option expected to be a string"); +- php_error_docref(NULL, E_WARNING, "enc_password option expected to be a string"); ++ zend_type_error("Option \"enc_password\" must be of type string, %s given", ++ zend_zval_type_name(option)); return -1; -@@ -373,7 +373,7 @@ static int php_zip_parse_options(zval *options, zip_options *opts) + } + opts->enc_password = Z_STRVAL_P(option); +@@ -373,49 +391,50 @@ static int php_zip_parse_options(zval *options, zip_options *opts) } #endif - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "remove_path", sizeof("remove_path") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "remove_path", sizeof("remove_path") - 1)) != NULL) { if (Z_TYPE_P(option) != IS_STRING) { - php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string"); +- php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string"); ++ zend_type_error("Option \"remove_path\" must be of type string, %s given", ++ zend_zval_type_name(option)); + return -1; + } + +- if (Z_STRLEN_P(option) < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string given as remove_path option"); ++ if (Z_STRLEN_P(option) == 0) { ++ zend_value_error("Option \"remove_path\" cannot be empty"); return -1; -@@ -393,7 +393,7 @@ static int php_zip_parse_options(zval *options, zip_options *opts) + } + + if (Z_STRLEN_P(option) >= MAXPATHLEN) { +- php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %d, %zd given)", +- MAXPATHLEN - 1, Z_STRLEN_P(option)); ++ zend_value_error("Option \"remove_path\" must be less than %d bytes", MAXPATHLEN - 1); + return -1; + } + opts->remove_path_len = Z_STRLEN_P(option); opts->remove_path = Z_STRVAL_P(option); } - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "add_path", sizeof("add_path") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "add_path", sizeof("add_path") - 1)) != NULL) { if (Z_TYPE_P(option) != IS_STRING) { - php_error_docref(NULL, E_WARNING, "add_path option expected to be a string"); +- php_error_docref(NULL, E_WARNING, "add_path option expected to be a string"); ++ zend_type_error("Option \"add_path\" must be of type string, %s given", ++ zend_zval_type_name(option)); + return -1; + } + +- if (Z_STRLEN_P(option) < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string given as the add_path option"); ++ if (Z_STRLEN_P(option) == 0) { ++ zend_value_error("Option \"add_path\" cannot be empty"); + return -1; + } + + if (Z_STRLEN_P(option) >= MAXPATHLEN) { +- php_error_docref(NULL, E_WARNING, "add_path string too long (max: %d, %zd given)", +- MAXPATHLEN - 1, Z_STRLEN_P(option)); ++ zend_value_error("Option \"add_path\" must be less than %d bytes", MAXPATHLEN - 1); return -1; -@@ -413,7 +413,7 @@ static int php_zip_parse_options(zval *options, zip_options *opts) + } + opts->add_path_len = Z_STRLEN_P(option); opts->add_path = Z_STRVAL_P(option); } - if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "flags", sizeof("flags") - 1)) != NULL) { + if ((option = zend_hash_str_find(options, "flags", sizeof("flags") - 1)) != NULL) { if (Z_TYPE_P(option) != IS_LONG) { - php_error_docref(NULL, E_WARNING, "flags option expected to be a integer"); +- php_error_docref(NULL, E_WARNING, "flags option expected to be a integer"); ++ zend_type_error("Option \"flags\" must be of type int, %s given", ++ zend_zval_type_name(option)); return -1; -@@ -1101,8 +1101,7 @@ static PHP_MSHUTDOWN_FUNCTION(zip); + } + opts->flags = Z_LVAL_P(option); +@@ -599,6 +618,7 @@ int php_zip_glob(char *pattern, int pattern_len, zend_long flags, zval *return_v + } + + if ((GLOB_AVAILABLE_FLAGS & flags) != flags) { ++ + php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform"); + return -1; + } +@@ -1101,8 +1121,7 @@ static PHP_MSHUTDOWN_FUNCTION(zip); static PHP_MINFO_FUNCTION(zip); /* }}} */ @@ -77,7 +160,7 @@ index f131966..841488b 100644 zend_module_entry zip_module_entry = { STANDARD_MODULE_HEADER, "zip", -@@ -1122,8 +1121,7 @@ ZEND_GET_MODULE(zip) +@@ -1122,8 +1141,7 @@ ZEND_GET_MODULE(zip) #endif /* set macro */ @@ -87,7 +170,18 @@ index f131966..841488b 100644 PHP_FUNCTION(zip_open) { char resolved_path[MAXPATHLEN + 1]; -@@ -1163,8 +1161,7 @@ PHP_FUNCTION(zip_open) +@@ -1136,8 +1154,8 @@ PHP_FUNCTION(zip_open) + } + + if (ZSTR_LEN(filename) == 0) { +- php_error_docref(NULL, E_WARNING, "Empty string as source"); +- RETURN_FALSE; ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + if (ZIP_OPENBASEDIR_CHECKPATH(ZSTR_VAL(filename))) { +@@ -1163,8 +1181,7 @@ PHP_FUNCTION(zip_open) } /* }}} */ @@ -97,7 +191,7 @@ index f131966..841488b 100644 PHP_FUNCTION(zip_close) { zval * zip; -@@ -1183,8 +1180,7 @@ PHP_FUNCTION(zip_close) +@@ -1183,8 +1200,7 @@ PHP_FUNCTION(zip_close) } /* }}} */ @@ -107,7 +201,7 @@ index f131966..841488b 100644 PHP_FUNCTION(zip_read) { zval *zip_dp; -@@ -1229,8 +1225,7 @@ PHP_FUNCTION(zip_read) +@@ -1229,8 +1245,7 @@ PHP_FUNCTION(zip_read) } /* }}} */ @@ -117,7 +211,7 @@ index f131966..841488b 100644 /* Dummy function to follow the old API */ PHP_FUNCTION(zip_entry_open) { -@@ -1261,8 +1256,7 @@ PHP_FUNCTION(zip_entry_open) +@@ -1261,8 +1276,7 @@ PHP_FUNCTION(zip_entry_open) } /* }}} */ @@ -127,7 +221,7 @@ index f131966..841488b 100644 PHP_FUNCTION(zip_entry_close) { zval * zip_entry; -@@ -1280,8 +1274,7 @@ PHP_FUNCTION(zip_entry_close) +@@ -1280,8 +1294,7 @@ PHP_FUNCTION(zip_entry_close) } /* }}} */ @@ -137,7 +231,7 @@ index f131966..841488b 100644 PHP_FUNCTION(zip_entry_read) { zval * zip_entry; -@@ -1374,40 +1367,35 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ +@@ -1374,40 +1387,35 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ } /* }}} */ @@ -183,7 +277,18 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, open) { struct zip *intern; -@@ -1452,16 +1440,20 @@ PHP_METHOD(ZipArchive, open) +@@ -1426,8 +1434,8 @@ PHP_METHOD(ZipArchive, open) + ze_obj = Z_ZIP_P(self); + + if (ZSTR_LEN(filename) == 0) { +- php_error_docref(NULL, E_WARNING, "Empty string as source"); +- RETURN_FALSE; ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + if (ZIP_OPENBASEDIR_CHECKPATH(ZSTR_VAL(filename))) { +@@ -1452,16 +1460,20 @@ PHP_METHOD(ZipArchive, open) ze_obj->filename = NULL; } @@ -207,7 +312,7 @@ index f131966..841488b 100644 flags |= ZIP_TRUNCATE; } } -@@ -1478,8 +1470,7 @@ PHP_METHOD(ZipArchive, open) +@@ -1478,8 +1490,7 @@ PHP_METHOD(ZipArchive, open) } /* }}} */ @@ -217,7 +322,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setPassword) { struct zip *intern; -@@ -1506,8 +1497,7 @@ PHP_METHOD(ZipArchive, setPassword) +@@ -1506,8 +1517,7 @@ PHP_METHOD(ZipArchive, setPassword) } /* }}} */ @@ -227,7 +332,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, close) { struct zip *intern; -@@ -1558,8 +1548,7 @@ PHP_METHOD(ZipArchive, close) +@@ -1558,8 +1568,7 @@ PHP_METHOD(ZipArchive, close) } /* }}} */ @@ -237,7 +342,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, count) { struct zip *intern; -@@ -1577,8 +1566,7 @@ PHP_METHOD(ZipArchive, count) +@@ -1577,8 +1586,7 @@ PHP_METHOD(ZipArchive, count) } /* }}} */ @@ -247,7 +352,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getStatusString) { zval *self = ZEND_THIS; -@@ -1621,8 +1609,7 @@ PHP_METHOD(ZipArchive, getStatusString) +@@ -1621,8 +1629,7 @@ PHP_METHOD(ZipArchive, getStatusString) } /* }}} */ @@ -257,7 +362,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, addEmptyDir) { struct zip *intern; -@@ -1671,19 +1658,19 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* +@@ -1671,30 +1678,30 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* char *path = "."; size_t path_len = 1; zend_long glob_flags = 0; @@ -280,16 +385,22 @@ index f131966..841488b 100644 &pattern, &path, &path_len, &options) == FAILURE) { RETURN_THROWS(); } -@@ -1693,7 +1680,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* - php_error_docref(NULL, E_NOTICE, "Empty string as pattern"); - RETURN_FALSE; + } + + if (ZSTR_LEN(pattern) == 0) { +- php_error_docref(NULL, E_NOTICE, "Empty string as pattern"); +- RETURN_FALSE; ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); } - if (options && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0 && (php_zip_parse_options(options, &opts) < 0)) { +- RETURN_FALSE; + if (options && zend_hash_num_elements(options) > 0 && (php_zip_parse_options(options, &opts) < 0)) { - RETURN_FALSE; ++ RETURN_THROWS(); } -@@ -1778,24 +1765,21 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* + if (type == 1) { +@@ -1778,24 +1785,21 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* } /* }}} */ @@ -317,7 +428,18 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, addFile) { zval *self = ZEND_THIS; -@@ -1829,8 +1813,7 @@ PHP_METHOD(ZipArchive, addFile) +@@ -1811,8 +1815,8 @@ PHP_METHOD(ZipArchive, addFile) + } + + if (ZSTR_LEN(filename) == 0) { +- php_error_docref(NULL, E_NOTICE, "Empty string as filename"); +- RETURN_FALSE; ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + if (entry_name_len == 0) { +@@ -1829,8 +1833,7 @@ PHP_METHOD(ZipArchive, addFile) } /* }}} */ @@ -327,7 +449,25 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, replaceFile) { zval *self = ZEND_THIS; -@@ -1863,8 +1846,7 @@ PHP_METHOD(ZipArchive, replaceFile) +@@ -1845,13 +1848,13 @@ PHP_METHOD(ZipArchive, replaceFile) + } + + if (ZSTR_LEN(filename) == 0) { +- php_error_docref(NULL, E_NOTICE, "Empty string as filename"); +- RETURN_FALSE; ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + if (index < 0) { +- php_error_docref(NULL, E_NOTICE, "Invalid negative index"); +- RETURN_FALSE; ++ zend_argument_value_error(2, "must be greater than or equal to 0"); ++ RETURN_THROWS(); + } + + if (php_zip_add_file(Z_ZIP_P(self), ZSTR_VAL(filename), ZSTR_LEN(filename), +@@ -1863,8 +1866,7 @@ PHP_METHOD(ZipArchive, replaceFile) } /* }}} */ @@ -337,7 +477,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, addFromString) { struct zip *intern; -@@ -1913,8 +1895,7 @@ PHP_METHOD(ZipArchive, addFromString) +@@ -1913,8 +1915,7 @@ PHP_METHOD(ZipArchive, addFromString) } /* }}} */ @@ -347,7 +487,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, statName) { struct zip *intern; -@@ -1935,8 +1916,7 @@ PHP_METHOD(ZipArchive, statName) +@@ -1935,8 +1936,7 @@ PHP_METHOD(ZipArchive, statName) } /* }}} */ @@ -357,7 +497,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, statIndex) { struct zip *intern; -@@ -1959,8 +1939,7 @@ PHP_METHOD(ZipArchive, statIndex) +@@ -1959,8 +1959,7 @@ PHP_METHOD(ZipArchive, statIndex) } /* }}} */ @@ -367,7 +507,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, locateName) { struct zip *intern; -@@ -1989,8 +1968,7 @@ PHP_METHOD(ZipArchive, locateName) +@@ -1989,8 +1988,7 @@ PHP_METHOD(ZipArchive, locateName) } /* }}} */ @@ -377,7 +517,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getNameIndex) { struct zip *intern; -@@ -2015,8 +1993,7 @@ PHP_METHOD(ZipArchive, getNameIndex) +@@ -2015,8 +2013,7 @@ PHP_METHOD(ZipArchive, getNameIndex) } /* }}} */ @@ -387,7 +527,18 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setArchiveComment) { struct zip *intern; -@@ -2043,8 +2020,7 @@ PHP_METHOD(ZipArchive, setArchiveComment) +@@ -2031,8 +2028,8 @@ PHP_METHOD(ZipArchive, setArchiveComment) + ZIP_FROM_OBJECT(intern, self); + + if (comment_len > 0xffff) { +- php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); +- RETURN_FALSE; ++ zend_argument_value_error(1, "must be less than 65535 bytes"); ++ RETURN_THROWS(); + } + + if (zip_set_archive_comment(intern, (const char *)comment, comment_len)) { +@@ -2043,8 +2040,7 @@ PHP_METHOD(ZipArchive, setArchiveComment) } /* }}} */ @@ -397,7 +548,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getArchiveComment) { struct zip *intern; -@@ -2067,8 +2043,7 @@ PHP_METHOD(ZipArchive, getArchiveComment) +@@ -2067,8 +2063,7 @@ PHP_METHOD(ZipArchive, getArchiveComment) } /* }}} */ @@ -407,7 +558,28 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setCommentName) { struct zip *intern; -@@ -2101,8 +2076,7 @@ PHP_METHOD(ZipArchive, setCommentName) +@@ -2082,15 +2077,16 @@ PHP_METHOD(ZipArchive, setCommentName) + RETURN_THROWS(); + } + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + ZIP_FROM_OBJECT(intern, self); + + if (comment_len > 0xffff) { +- php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); +- RETURN_FALSE; ++ zend_argument_value_error(2, "must be less than 65535 bytes"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); +@@ -2101,8 +2097,7 @@ PHP_METHOD(ZipArchive, setCommentName) } /* }}} */ @@ -417,7 +589,18 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setCommentIndex) { struct zip *intern; -@@ -2132,8 +2106,7 @@ PHP_METHOD(ZipArchive, setCommentIndex) +@@ -2120,8 +2115,8 @@ PHP_METHOD(ZipArchive, setCommentIndex) + ZIP_FROM_OBJECT(intern, self); + + if (comment_len > 0xffff) { +- php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); +- RETURN_FALSE; ++ zend_argument_value_error(2, "must be less than 65535 bytes"); ++ RETURN_THROWS(); + } + + PHP_ZIP_STAT_INDEX(intern, index, 0, sb); +@@ -2132,8 +2127,7 @@ PHP_METHOD(ZipArchive, setCommentIndex) /* those constants/functions are only available in libzip since 0.11.2 */ #ifdef ZIP_OPSYS_DEFAULT @@ -427,7 +610,23 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setExternalAttributesName) { struct zip *intern; -@@ -2166,8 +2139,7 @@ PHP_METHOD(ZipArchive, setExternalAttributesName) +@@ -2150,11 +2144,13 @@ PHP_METHOD(ZipArchive, setExternalAttributesName) + + ZIP_FROM_OBJECT(intern, self); + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); ++ + if (idx < 0) { + RETURN_FALSE; + } +@@ -2166,8 +2162,7 @@ PHP_METHOD(ZipArchive, setExternalAttributesName) } /* }}} */ @@ -437,7 +636,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setExternalAttributesIndex) { struct zip *intern; -@@ -2191,8 +2163,7 @@ PHP_METHOD(ZipArchive, setExternalAttributesIndex) +@@ -2191,8 +2186,7 @@ PHP_METHOD(ZipArchive, setExternalAttributesIndex) } /* }}} */ @@ -447,7 +646,23 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getExternalAttributesName) { struct zip *intern; -@@ -2229,8 +2200,7 @@ PHP_METHOD(ZipArchive, getExternalAttributesName) +@@ -2211,11 +2205,13 @@ PHP_METHOD(ZipArchive, getExternalAttributesName) + + ZIP_FROM_OBJECT(intern, self); + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); ++ + if (idx < 0) { + RETURN_FALSE; + } +@@ -2229,8 +2225,7 @@ PHP_METHOD(ZipArchive, getExternalAttributesName) } /* }}} */ @@ -457,7 +672,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getExternalAttributesIndex) { struct zip *intern; -@@ -2260,8 +2230,7 @@ PHP_METHOD(ZipArchive, getExternalAttributesIndex) +@@ -2260,8 +2255,7 @@ PHP_METHOD(ZipArchive, getExternalAttributesIndex) #endif /* ifdef ZIP_OPSYS_DEFAULT */ #ifdef HAVE_ENCRYPTION @@ -467,7 +682,23 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setEncryptionName) { struct zip *intern; -@@ -2294,8 +2263,7 @@ PHP_METHOD(ZipArchive, setEncryptionName) +@@ -2278,11 +2272,13 @@ PHP_METHOD(ZipArchive, setEncryptionName) + + ZIP_FROM_OBJECT(intern, self); + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); ++ + if (idx < 0) { + RETURN_FALSE; + } +@@ -2294,8 +2290,7 @@ PHP_METHOD(ZipArchive, setEncryptionName) } /* }}} */ @@ -477,7 +708,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setEncryptionIndex) { struct zip *intern; -@@ -2319,8 +2287,7 @@ PHP_METHOD(ZipArchive, setEncryptionIndex) +@@ -2319,8 +2314,7 @@ PHP_METHOD(ZipArchive, setEncryptionIndex) /* }}} */ #endif @@ -487,7 +718,24 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getCommentName) { struct zip *intern; -@@ -2354,8 +2321,7 @@ PHP_METHOD(ZipArchive, getCommentName) +@@ -2339,12 +2333,13 @@ PHP_METHOD(ZipArchive, getCommentName) + + ZIP_FROM_OBJECT(intern, self); + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); +- RETURN_FALSE; ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); ++ + if (idx < 0) { + RETURN_FALSE; + } +@@ -2354,8 +2349,7 @@ PHP_METHOD(ZipArchive, getCommentName) } /* }}} */ @@ -497,7 +745,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getCommentIndex) { struct zip *intern; -@@ -2378,8 +2344,7 @@ PHP_METHOD(ZipArchive, getCommentIndex) +@@ -2378,10 +2372,9 @@ PHP_METHOD(ZipArchive, getCommentIndex) } /* }}} */ @@ -505,9 +753,28 @@ index f131966..841488b 100644 -Set the compression of a file in zip, using its name */ +/* {{{ Set the compression of a file in zip, using its name */ PHP_METHOD(ZipArchive, setCompressionName) - { +- { ++{ struct zip *intern; -@@ -2413,8 +2378,7 @@ PHP_METHOD(ZipArchive, setCompressionName) + zval *this = ZEND_THIS; + size_t name_len; +@@ -2396,11 +2389,13 @@ PHP_METHOD(ZipArchive, setCompressionName) + + ZIP_FROM_OBJECT(intern, this); + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); ++ + if (idx < 0) { + RETURN_FALSE; + } +@@ -2413,8 +2408,7 @@ PHP_METHOD(ZipArchive, setCompressionName) } /* }}} */ @@ -517,7 +784,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setCompressionIndex) { struct zip *intern; -@@ -2438,8 +2402,7 @@ PHP_METHOD(ZipArchive, setCompressionIndex) +@@ -2438,10 +2432,9 @@ PHP_METHOD(ZipArchive, setCompressionIndex) /* }}} */ #ifdef HAVE_SET_MTIME @@ -525,9 +792,28 @@ index f131966..841488b 100644 -Set the modification time of a file in zip, using its name */ +/* {{{ Set the modification time of a file in zip, using its name */ PHP_METHOD(ZipArchive, setMtimeName) - { +- { ++{ struct zip *intern; -@@ -2473,8 +2436,7 @@ PHP_METHOD(ZipArchive, setMtimeName) + zval *this = ZEND_THIS; + size_t name_len; +@@ -2456,11 +2449,13 @@ PHP_METHOD(ZipArchive, setMtimeName) + + ZIP_FROM_OBJECT(intern, this); + +- if (name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); ++ if (name_len == 0) { ++ zend_argument_value_error(1, "cannot be empty"); ++ RETURN_THROWS(); + } + + idx = zip_name_locate(intern, name, 0); ++ + if (idx < 0) { + RETURN_FALSE; + } +@@ -2473,8 +2468,7 @@ PHP_METHOD(ZipArchive, setMtimeName) } /* }}} */ @@ -537,7 +823,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, setMtimeIndex) { struct zip *intern; -@@ -2498,8 +2460,7 @@ PHP_METHOD(ZipArchive, setMtimeIndex) +@@ -2498,8 +2492,7 @@ PHP_METHOD(ZipArchive, setMtimeIndex) /* }}} */ #endif @@ -547,7 +833,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, deleteIndex) { struct zip *intern; -@@ -2524,8 +2485,7 @@ PHP_METHOD(ZipArchive, deleteIndex) +@@ -2524,8 +2517,7 @@ PHP_METHOD(ZipArchive, deleteIndex) } /* }}} */ @@ -557,7 +843,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, deleteName) { struct zip *intern; -@@ -2552,8 +2512,7 @@ PHP_METHOD(ZipArchive, deleteName) +@@ -2552,8 +2544,7 @@ PHP_METHOD(ZipArchive, deleteName) } /* }}} */ @@ -567,7 +853,20 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, renameIndex) { struct zip *intern; -@@ -2585,8 +2544,7 @@ PHP_METHOD(ZipArchive, renameIndex) +@@ -2572,9 +2563,9 @@ PHP_METHOD(ZipArchive, renameIndex) + + ZIP_FROM_OBJECT(intern, self); + +- if (new_name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as new entry name"); +- RETURN_FALSE; ++ if (new_name_len == 0) { ++ zend_argument_value_error(2, "cannot be empty"); ++ RETURN_THROWS(); + } + + if (zip_file_rename(intern, index, (const char *)new_name, 0) != 0) { +@@ -2585,8 +2576,7 @@ PHP_METHOD(ZipArchive, renameIndex) } /* }}} */ @@ -577,7 +876,20 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, renameName) { struct zip *intern; -@@ -2616,8 +2574,7 @@ PHP_METHOD(ZipArchive, renameName) +@@ -2601,9 +2591,9 @@ PHP_METHOD(ZipArchive, renameName) + + ZIP_FROM_OBJECT(intern, self); + +- if (new_name_len < 1) { +- php_error_docref(NULL, E_NOTICE, "Empty string as new entry name"); +- RETURN_FALSE; ++ if (new_name_len == 0) { ++ zend_argument_value_error(2, "cannot be empty"); ++ RETURN_THROWS(); + } + + PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb); +@@ -2616,8 +2606,7 @@ PHP_METHOD(ZipArchive, renameName) } /* }}} */ @@ -587,7 +899,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, unchangeIndex) { struct zip *intern; -@@ -2642,8 +2599,7 @@ PHP_METHOD(ZipArchive, unchangeIndex) +@@ -2642,8 +2631,7 @@ PHP_METHOD(ZipArchive, unchangeIndex) } /* }}} */ @@ -597,7 +909,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, unchangeName) { struct zip *intern; -@@ -2672,8 +2628,7 @@ PHP_METHOD(ZipArchive, unchangeName) +@@ -2672,8 +2660,7 @@ PHP_METHOD(ZipArchive, unchangeName) } /* }}} */ @@ -607,7 +919,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, unchangeAll) { struct zip *intern; -@@ -2693,8 +2648,7 @@ PHP_METHOD(ZipArchive, unchangeAll) +@@ -2693,8 +2680,7 @@ PHP_METHOD(ZipArchive, unchangeAll) } /* }}} */ @@ -617,7 +929,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, unchangeArchive) { struct zip *intern; -@@ -2714,8 +2668,7 @@ PHP_METHOD(ZipArchive, unchangeArchive) +@@ -2714,8 +2700,7 @@ PHP_METHOD(ZipArchive, unchangeArchive) } /* }}} */ @@ -627,7 +939,7 @@ index f131966..841488b 100644 /* TODO: * - allow index or array of indices * - replace path -@@ -2868,24 +2821,21 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ +@@ -2868,24 +2853,21 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ } /* }}} */ @@ -655,7 +967,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, getStream) { struct zip *intern; -@@ -2925,13 +2875,12 @@ static void _php_zip_progress_callback(zip_t *arch, double state, void *ptr) +@@ -2925,35 +2907,23 @@ static void _php_zip_progress_callback(zip_t *arch, double state, void *ptr) ze_zip_object *obj = ptr; ZVAL_DOUBLE(&cb_args[0], state); @@ -671,7 +983,43 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, registerProgressCallback) { struct zip *intern; -@@ -2981,7 +2930,7 @@ static int _php_zip_cancel_callback(zip_t *arch, void *ptr) +- zval *self = getThis(); ++ zval *self = ZEND_THIS; + double rate; +- zval *callback; ++ zend_fcall_info fci; ++ zend_fcall_info_cache fcc; + ze_zip_object *obj; + +- if (!self) { +- RETURN_FALSE; +- } +- +- if (zend_parse_parameters(ZEND_NUM_ARGS(), "dz", &rate, &callback) == FAILURE) { +- return; +- } +- +- /* callable? */ +- if (!zend_is_callable(callback, 0, NULL)) { +- zend_string *callback_name = zend_get_callable_name(callback); +- php_error_docref(NULL, E_WARNING, "Invalid callback '%s'", ZSTR_VAL(callback_name)); +- zend_string_release_ex(callback_name, 0); +- RETURN_FALSE; ++ if (zend_parse_parameters(ZEND_NUM_ARGS(), "df", &rate, &fci, &fcc) == FAILURE) { ++ RETURN_THROWS(); + } + + ZIP_FROM_OBJECT(intern, self); +@@ -2964,7 +2934,7 @@ PHP_METHOD(ZipArchive, registerProgressCallback) + _php_zip_progress_callback_free(obj); + + /* register */ +- ZVAL_COPY(&obj->progress_callback, callback); ++ ZVAL_COPY(&obj->progress_callback, &fci.function_name); + if (zip_register_progress_callback_with_state(intern, rate, _php_zip_progress_callback, _php_zip_progress_callback_free, obj)) { + RETURN_FALSE; + } +@@ -2981,7 +2951,7 @@ static int _php_zip_cancel_callback(zip_t *arch, void *ptr) int retval = 0; ze_zip_object *obj = ptr; @@ -680,7 +1028,7 @@ index f131966..841488b 100644 retval = zval_get_long(&cb_retval); zval_ptr_dtor(&cb_retval); } -@@ -2989,8 +2938,7 @@ static int _php_zip_cancel_callback(zip_t *arch, void *ptr) +@@ -2989,40 +2959,27 @@ static int _php_zip_cancel_callback(zip_t *arch, void *ptr) return retval; } @@ -690,7 +1038,45 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, registerCancelCallback) { struct zip *intern; -@@ -3033,8 +2981,7 @@ PHP_METHOD(ZipArchive, registerCancelCallback) +- zval *self = getThis(); +- zval *callback; ++ zval *self = ZEND_THIS; ++ zend_fcall_info fci; ++ zend_fcall_info_cache fcc; + ze_zip_object *obj; +- +- if (!self) { +- RETURN_FALSE; +- } +- +- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback) == FAILURE) { +- return; ++ if (zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fci, &fcc) == FAILURE) { ++ RETURN_THROWS(); + } + + ZIP_FROM_OBJECT(intern, self); + +- /* callable? */ +- if (!zend_is_callable(callback, 0, NULL)) { +- zend_string *callback_name = zend_get_callable_name(callback); +- php_error_docref(NULL, E_WARNING, "Invalid callback '%s'", ZSTR_VAL(callback_name)); +- zend_string_release_ex(callback_name, 0); +- RETURN_FALSE; +- } +- + obj = Z_ZIP_P(self); + + /* free if called twice */ + _php_zip_cancel_callback_free(obj); + + /* register */ +- ZVAL_COPY(&obj->cancel_callback, callback); ++ ZVAL_COPY(&obj->cancel_callback, &fci.function_name); + if (zip_register_cancel_callback_with_state(intern, _php_zip_cancel_callback, _php_zip_cancel_callback_free, obj)) { + RETURN_FALSE; + } +@@ -3033,8 +2990,7 @@ PHP_METHOD(ZipArchive, registerCancelCallback) #endif #ifdef HAVE_METHOD_SUPPORTED @@ -700,7 +1086,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, isCompressionMethodSupported) { zend_long method; -@@ -3047,8 +2994,7 @@ PHP_METHOD(ZipArchive, isCompressionMethodSupported) +@@ -3047,8 +3003,7 @@ PHP_METHOD(ZipArchive, isCompressionMethodSupported) } /* }}} */ @@ -710,7 +1096,7 @@ index f131966..841488b 100644 PHP_METHOD(ZipArchive, isEncryptionMethodSupported) { zend_long method; -@@ -3136,6 +3082,9 @@ static PHP_MINIT_FUNCTION(zip) +@@ -3136,6 +3091,9 @@ static PHP_MINIT_FUNCTION(zip) #ifdef ZIP_CM_LZMA2 REGISTER_ZIP_CLASS_CONST_LONG("CM_LZMA2", ZIP_CM_LZMA2); #endif @@ -720,7 +1106,7 @@ index f131966..841488b 100644 #ifdef ZIP_CM_XZ REGISTER_ZIP_CLASS_CONST_LONG("CM_XZ", ZIP_CM_XZ); #endif -@@ -3240,8 +3189,7 @@ static PHP_MINIT_FUNCTION(zip) +@@ -3240,8 +3198,7 @@ static PHP_MINIT_FUNCTION(zip) } /* }}} */ @@ -730,7 +1116,7 @@ index f131966..841488b 100644 static PHP_MSHUTDOWN_FUNCTION(zip) { zend_hash_destroy(&zip_prop_handlers); -@@ -3250,8 +3198,7 @@ static PHP_MSHUTDOWN_FUNCTION(zip) +@@ -3250,8 +3207,7 @@ static PHP_MSHUTDOWN_FUNCTION(zip) } /* }}} */ @@ -740,8 +1126,21 @@ index f131966..841488b 100644 static PHP_MINFO_FUNCTION(zip) { php_info_print_table_start(); +diff --git a/php8/php_zip.h b/php8/php_zip.h +index ddc35df..92df580 100644 +--- a/php8/php_zip.h ++++ b/php8/php_zip.h +@@ -31,7 +31,7 @@ extern zend_module_entry zip_module_entry; + #define ZIP_OVERWRITE ZIP_TRUNCATE + #endif + +-#define PHP_ZIP_VERSION "1.19.0" ++#define PHP_ZIP_VERSION "1.19.1-dev" + + #define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename) + diff --git a/php8/php_zip.stub.php b/php8/php_zip.stub.php -index da8e373..4d9ba27 100644 +index da8e373..01f055f 100644 --- a/php8/php_zip.stub.php +++ b/php8/php_zip.stub.php @@ -2,44 +2,66 @@ @@ -817,7 +1216,28 @@ index da8e373..4d9ba27 100644 function zip_entry_compressionmethod($zip_entry): string|false {} class ZipArchive -@@ -194,9 +216,9 @@ class ZipArchive +@@ -161,10 +183,18 @@ class ZipArchive + /** @return bool */ + public function setExternalAttributesIndex(int $index, int $opsys, int $attr, int $flags = 0) {} + +- /** @return bool */ ++ /** ++ * @param int $opsys ++ * @param int $attr ++ * @return bool ++ */ + public function getExternalAttributesName(string $name, &$opsys, &$attr, int $flags = 0) {} + +- /** @return bool */ ++ /** ++ * @param int $opsys ++ * @param int $attr ++ * @return bool ++ */ + public function getExternalAttributesIndex(int $index, &$opsys, &$attr, int $flags = 0) {} + #endif + +@@ -194,9 +224,9 @@ class ZipArchive #ifdef HAVE_METHOD_SUPPORTED /** @return bool */ @@ -830,13 +1250,13 @@ index da8e373..4d9ba27 100644 #endif } diff --git a/php8/php_zip_arginfo.h b/php8/php_zip_arginfo.h -index c1e8f24..25157d8 100644 +index c1e8f24..87222c9 100644 --- a/php8/php_zip_arginfo.h +++ b/php8/php_zip_arginfo.h @@ -1,4 +1,5 @@ -/* This is a generated file, edit the .stub.php file instead. */ +/* This is a generated file, edit the .stub.php file instead. -+ * Stub hash: 95608dd1d6c2ad80ada990a9e939b76dba705d48 */ ++ * Stub hash: 880148896a71ad9bd076bb42c735ff1b83cd0731 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_zip_open, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -958,6 +1378,172 @@ index 56cc37c..7770f64 100644 --FILE-- <?php +diff --git a/tests/oo_getcomment2.phpt b/tests/oo_getcomment2.phpt +index 89570a3..113c6b6 100644 +--- a/tests/oo_getcomment2.phpt ++++ b/tests/oo_getcomment2.phpt +@@ -17,16 +17,20 @@ if (!$zip->open($file)) { + echo $zip->getArchiveComment() . "\n"; + + $idx = $zip->locateName('foo'); +-echo $zip->getCommentName('foo') . "\n"; +-echo $zip->getCommentIndex($idx); ++var_dump($zip->getCommentName('foo')); ++var_dump($zip->getCommentIndex($idx)); + +-echo $zip->getCommentName('') . "\n"; ++try { ++ echo $zip->getCommentName('') . "\n"; ++} catch (\ValueError $e) { ++ echo $e->getMessage() . \PHP_EOL; ++} + + $zip->close(); + + ?> +---EXPECTF-- ++--EXPECT-- + Zip archive comment +-foo comment +-foo comment +-Notice: ZipArchive::getCommentName(): Empty string as entry name in %s on line %d ++string(11) "foo comment" ++string(11) "foo comment" ++ZipArchive::getCommentName(): Argument #1 ($name) cannot be empty +diff --git a/tests/oo_open.phpt b/tests/oo_open.phpt +index 0760db3..bd251e7 100644 +--- a/tests/oo_open.phpt ++++ b/tests/oo_open.phpt +@@ -4,6 +4,7 @@ zip::open() function + <?php + /* $Id$ */ + if(!extension_loaded('zip')) die('skip'); ++if (PHP_VERSION_ID >= 80000) die('skip PHP < 8 only'); + ?> + --FILE-- + <?php +diff --git a/tests/oo_open2.phpt b/tests/oo_open2.phpt +new file mode 100644 +index 0000000..337b8c6 +--- /dev/null ++++ b/tests/oo_open2.phpt +@@ -0,0 +1,49 @@ ++--TEST-- ++zip::open() function ++--SKIPIF-- ++<?php ++if(!extension_loaded('zip')) die('skip'); ++if (PHP_VERSION_ID < 80000) die('skip PHP 8 only'); ++?> ++--FILE-- ++<?php ++ ++$dirname = __DIR__ . '/'; ++$zip = new ZipArchive; ++$r = $zip->open($dirname . 'nofile'); ++if ($r !== TRUE) { ++ echo "ER_OPEN: ok\n"; ++} else { ++ echo "ER_OPEN: FAILED\n"; ++} ++ ++$r = $zip->open($dirname . 'nofile', ZIPARCHIVE::CREATE); ++if (!$r) { ++ echo "create: failed\n"; ++} else { ++ echo "create: ok\n"; ++} ++@unlink($dirname . 'nofile'); ++ ++$zip = new ZipArchive; ++try { ++ $zip->open(''); ++} catch (\ValueError $e) { ++ echo $e->getMessage() . \PHP_EOL; ++} ++ ++if (!$zip->open($dirname . 'test.zip')) { ++ exit("failed 1\n"); ++} ++ ++if ($zip->status == ZIPARCHIVE::ER_OK) { ++ echo "OK\n"; ++} else { ++ echo "failed\n"; ++} ++?> ++--EXPECT-- ++ER_OPEN: ok ++create: ok ++ZipArchive::open(): Argument #1 ($filename) cannot be empty ++OK +diff --git a/tests/oo_setcomment_error.phpt b/tests/oo_setcomment_error.phpt +index a8f1e47..b5b251b 100644 +--- a/tests/oo_setcomment_error.phpt ++++ b/tests/oo_setcomment_error.phpt +@@ -3,6 +3,7 @@ setComment error behavior + --SKIPIF-- + <?php + if(!extension_loaded('zip')) die('skip zip extension not available'); ++if (PHP_VERSION_ID >= 80000) die('skip PHP < 8 only'); + ?> + --FILE-- + <?php +diff --git a/tests/oo_setcomment_error2.phpt b/tests/oo_setcomment_error2.phpt +new file mode 100644 +index 0000000..9622e0f +--- /dev/null ++++ b/tests/oo_setcomment_error2.phpt +@@ -0,0 +1,49 @@ ++--TEST-- ++setComment error behavior ++--SKIPIF-- ++<?php ++if(!extension_loaded('zip')) die('skip zip extension not available'); ++if (PHP_VERSION_ID < 80000) die('skip PHP 8 only'); ++?> ++--FILE-- ++<?php ++$file = __DIR__ . '/__tmp_oo_set_comment_error.zip'; ++ ++@unlink($file); ++ ++$zip = new ZipArchive; ++if (!$zip->open($file, ZIPARCHIVE::CREATE)) { ++ exit('failed'); ++} ++ ++$zip->addFromString('entry1.txt', 'entry #1'); ++$zip->addFromString('entry2.txt', 'entry #2'); ++ ++$longComment = str_repeat('a', 0x10000); ++ ++try { ++ var_dump($zip->setArchiveComment($longComment)); ++} catch (\ValueError $e) { ++ echo $e->getMessage() . \PHP_EOL; ++} ++try { ++ var_dump($zip->setCommentName('entry1.txt', $longComment)); ++} catch (\ValueError $e) { ++ echo $e->getMessage() . \PHP_EOL; ++} ++try { ++ var_dump($zip->setCommentIndex(1, $longComment)); ++} catch (\ValueError $e) { ++ echo $e->getMessage() . \PHP_EOL; ++} ++ ++$zip->close(); ++?> ++--EXPECT-- ++ZipArchive::setArchiveComment(): Argument #1 ($comment) must be less than 65535 bytes ++ZipArchive::setCommentName(): Argument #2 ($comment) must be less than 65535 bytes ++ZipArchive::setCommentIndex(): Argument #2 ($comment) must be less than 65535 bytes ++--CLEAN-- ++<?php ++@unlink(__DIR__ . '/__tmp_oo_set_comment_error.zip'); ++?> diff --git a/tests/oo_setcompression.phpt b/tests/oo_setcompression.phpt index 8a746a8..fd5fb54 100644 --- a/tests/oo_setcompression.phpt @@ -1114,3 +1700,40 @@ index 5cadb2d..af72879 100644 --FILE-- <?php $zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +diff --git a/tests/zip_open_error2.phpt b/tests/zip_open_error2.phpt +new file mode 100644 +index 0000000..01e0e20 +--- /dev/null ++++ b/tests/zip_open_error2.phpt +@@ -0,0 +1,31 @@ ++--TEST-- ++zip_open() error conditions ++--CREDITS-- ++Birgitte Kvarme <bitta@redpill-linpro.com> ++#PHPTestFest2009 Norway 2009-06-09 \o/ ++--SKIPIF-- ++<?php ++if(!extension_loaded('zip')) die('skip'); ++if (PHP_VERSION_ID < 80000) die('skip PHP 8 only'); ++?> ++--FILE-- ++<?php ++echo "Test case 1:"; ++try { ++ $zip = zip_open(""); ++} catch (\ValueError $e) { ++ echo $e->getMessage() . \PHP_EOL; ++} ++ ++echo "Test case 2:\n"; ++$zip = zip_open("/non_exisitng_directory/test_procedural.zip"); ++echo is_resource($zip) ? "OK" : "Failure"; ++?> ++--EXPECTF-- ++Test case 1: ++Deprecated: Function zip_open() is deprecated in %s on line %d ++zip_open(): Argument #1 ($filename) cannot be empty ++Test case 2: ++ ++Deprecated: Function zip_open() is deprecated in %s on line %d ++Failure |