From 44192ce80b72c9aaf4aa1af80d14a42ae203d608 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 9 Feb 2021 12:55:33 +0100 Subject: [PATCH] Make Phar $fileNotFoundScript nullable While "" is already treated the same way as absence, null is the logically correct default here. Making this one argument non-nullable is particularly pecular when considering that the preceding $alias and $index arguments are both nullable. --- ext/phar/phar_object.c | 2 +- ext/phar/phar_object.stub.php | 4 ++-- ext/phar/phar_object_arginfo.h | 4 ++-- ext/phar/tests/cache_list/frontcontroller12.phpt | 2 +- ext/phar/tests/cache_list/frontcontroller13.phpt | 2 +- ext/phar/tests/cache_list/frontcontroller31.phpt | 2 +- ext/phar/tests/frontcontroller12.phpt | 2 +- ext/phar/tests/frontcontroller13.phpt | 2 +- ext/phar/tests/frontcontroller31.phpt | 2 +- ext/phar/tests/tar/frontcontroller12.phar.phpt | 2 +- ext/phar/tests/tar/frontcontroller13.phar.phpt | 2 +- ext/phar/tests/zip/frontcontroller12.phar.phpt | 2 +- ext/phar/tests/zip/frontcontroller13.phar.phpt | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index e45c187efa4bb..5fe9e26af0b92 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -552,7 +552,7 @@ PHP_METHOD(Phar, webPhar) phar_entry_info *info = NULL; size_t sapi_mod_name_len = strlen(sapi_module.name); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!saf!", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!af!", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) { RETURN_THROWS(); } diff --git a/ext/phar/phar_object.stub.php b/ext/phar/phar_object.stub.php index 31663e4b8c687..5a1122c74ffce 100644 --- a/ext/phar/phar_object.stub.php +++ b/ext/phar/phar_object.stub.php @@ -174,7 +174,7 @@ final public static function mungServer(array $variables): void {} final public static function unlinkArchive(string $filename): bool {} final public static function webPhar( - ?string $alias = null, ?string $index = null, string $fileNotFoundScript = "", + ?string $alias = null, ?string $index = null, ?string $fileNotFoundScript = null, array $mimeTypes = [], ?callable $rewrite = null): void {} } @@ -470,7 +470,7 @@ final public static function unlinkArchive(string $filename): bool {} /** @implementation-alias Phar::webPhar */ final public static function webPhar( - ?string $alias = null, ?string $index = null, string $fileNotFoundScript = "", + ?string $alias = null, ?string $index = null, ?string $fileNotFoundScript = null, array $mimeTypes = [], ?callable $rewrite = null): void {} } diff --git a/ext/phar/phar_object_arginfo.h b/ext/phar/phar_object_arginfo.h index dd4b8aba7590b..ade8f874abae9 100644 --- a/ext/phar/phar_object_arginfo.h +++ b/ext/phar/phar_object_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3575a0330ff6102461655bc84add44e8b08b585f */ + * Stub hash: a8562e63010e127aadb97134733ac328ced3c7bf */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Phar___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -204,7 +204,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Phar_webPhar, 0, 0, IS_VOID, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, alias, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, index, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fileNotFoundScript, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fileNotFoundScript, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mimeTypes, IS_ARRAY, 0, "[]") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, rewrite, IS_CALLABLE, 1, "null") ZEND_END_ARG_INFO() diff --git a/ext/phar/tests/cache_list/frontcontroller12.phpt b/ext/phar/tests/cache_list/frontcontroller12.phpt index 8b78e62c9cd5b..857b7dc875869 100644 --- a/ext/phar/tests/cache_list/frontcontroller12.phpt +++ b/ext/phar/tests/cache_list/frontcontroller12.phpt @@ -16,6 +16,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.php:2 Stack trace: -#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller12.php on line 2 diff --git a/ext/phar/tests/cache_list/frontcontroller13.phpt b/ext/phar/tests/cache_list/frontcontroller13.phpt index 9d2f9105dac01..ddbab34c07a3f 100644 --- a/ext/phar/tests/cache_list/frontcontroller13.phpt +++ b/ext/phar/tests/cache_list/frontcontroller13.phpt @@ -16,6 +16,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.php:2 Stack trace: -#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller13.php on line 2 diff --git a/ext/phar/tests/cache_list/frontcontroller31.phpt b/ext/phar/tests/cache_list/frontcontroller31.phpt index 41e36bf669962..3419bb381d6f5 100644 --- a/ext/phar/tests/cache_list/frontcontroller31.phpt +++ b/ext/phar/tests/cache_list/frontcontroller31.phpt @@ -15,6 +15,6 @@ files/frontcontroller16.phar --EXPECTF-- Fatal error: Uncaught TypeError: Phar::webPhar(): Argument #5 ($rewrite) must be a valid callback or null, class "fail" not found in %s:%d Stack trace: -#0 %s(%d): Phar::webPhar('test.phar', '/index.php', '', Array, Array) +#0 %s(%d): Phar::webPhar('test.phar', '/index.php', NULL, Array, Array) #1 {main} thrown in %s on line %d diff --git a/ext/phar/tests/frontcontroller12.phpt b/ext/phar/tests/frontcontroller12.phpt index a7b1a892d6c3c..40bd8e333f97e 100644 --- a/ext/phar/tests/frontcontroller12.phpt +++ b/ext/phar/tests/frontcontroller12.phpt @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.php:2 Stack trace: -#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller12.php on line 2 diff --git a/ext/phar/tests/frontcontroller13.phpt b/ext/phar/tests/frontcontroller13.phpt index 99b769d406301..60d5709c6f351 100644 --- a/ext/phar/tests/frontcontroller13.phpt +++ b/ext/phar/tests/frontcontroller13.phpt @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.php:2 Stack trace: -#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller13.php on line 2 diff --git a/ext/phar/tests/frontcontroller31.phpt b/ext/phar/tests/frontcontroller31.phpt index 721df4849cf48..121a9389ee8d7 100644 --- a/ext/phar/tests/frontcontroller31.phpt +++ b/ext/phar/tests/frontcontroller31.phpt @@ -14,6 +14,6 @@ files/frontcontroller16.phar --EXPECTF-- Fatal error: Uncaught TypeError: Phar::webPhar(): Argument #5 ($rewrite) must be a valid callback or null, class "fail" not found in %s:%d Stack trace: -#0 %s(%d): Phar::webPhar('test.phar', '/index.php', '', Array, Array) +#0 %s(%d): Phar::webPhar('test.phar', '/index.php', NULL, Array, Array) #1 {main} thrown in %s on line %d diff --git a/ext/phar/tests/tar/frontcontroller12.phar.phpt b/ext/phar/tests/tar/frontcontroller12.phar.phpt index cbb928ff77e91..cec426b05aef7 100644 --- a/ext/phar/tests/tar/frontcontroller12.phar.phpt +++ b/ext/phar/tests/tar/frontcontroller12.phar.phpt @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.phar.php:2 Stack trace: -#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller12.phar.php on line 2 diff --git a/ext/phar/tests/tar/frontcontroller13.phar.phpt b/ext/phar/tests/tar/frontcontroller13.phar.phpt index 107961a70fbe7..7d9992cb9d8a3 100644 --- a/ext/phar/tests/tar/frontcontroller13.phar.phpt +++ b/ext/phar/tests/tar/frontcontroller13.phar.phpt @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.phar.php:2 Stack trace: -#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller13.phar.php on line 2 diff --git a/ext/phar/tests/zip/frontcontroller12.phar.phpt b/ext/phar/tests/zip/frontcontroller12.phar.phpt index 9f5b0a13aa988..2169264b64907 100644 --- a/ext/phar/tests/zip/frontcontroller12.phar.phpt +++ b/ext/phar/tests/zip/frontcontroller12.phar.phpt @@ -17,6 +17,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.phar.php:2 Stack trace: -#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller12.phar.php on line 2 diff --git a/ext/phar/tests/zip/frontcontroller13.phar.phpt b/ext/phar/tests/zip/frontcontroller13.phar.phpt index 5d2a77e4ac255..c9c72a7a60247 100644 --- a/ext/phar/tests/zip/frontcontroller13.phar.phpt +++ b/ext/phar/tests/zip/frontcontroller13.phar.phpt @@ -17,6 +17,6 @@ Content-type: text/html; charset=UTF-8 --EXPECTF-- Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.phar.php:2 Stack trace: -#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array) #1 {main} thrown in %sfrontcontroller13.phar.php on line 2