From: Nikita Popov Date: Mon, 30 Mar 2020 14:26:28 +0000 (+0200) Subject: mb_detect_order(): Use proper array|string argument X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a2ce27bbab3e763afad0efc99c268b174623e7e;p=php mb_detect_order(): Use proper array|string argument --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index a0f4a0b24d..4f698a7a47 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -1530,13 +1530,15 @@ PHP_FUNCTION(mb_http_output) Sets the current detect_order or Return the current detect_order as a array */ PHP_FUNCTION(mb_detect_order) { - zval *arg1 = NULL; + zend_string *order_str = NULL; + HashTable *order_ht = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg1) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_ARRAY_HT(order_str, order_ht) + ZEND_PARSE_PARAMETERS_END(); - if (!arg1) { + if (!order_str && !order_ht) { size_t i; size_t n = MBSTRG(current_detect_order_list_size); const mbfl_encoding **entry = MBSTRG(current_detect_order_list); @@ -1546,22 +1548,16 @@ PHP_FUNCTION(mb_detect_order) entry++; } } else { - const mbfl_encoding **list = NULL; - size_t size = 0; - switch (Z_TYPE_P(arg1)) { - case IS_ARRAY: - if (FAILURE == php_mb_parse_encoding_array(Z_ARRVAL_P(arg1), &list, &size)) { - RETURN_FALSE; - } - break; - default: - if (!try_convert_to_string(arg1)) { - RETURN_THROWS(); - } - if (FAILURE == php_mb_parse_encoding_list(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), &list, &size, 0)) { - RETURN_FALSE; - } - break; + const mbfl_encoding **list; + size_t size; + if (order_ht) { + if (FAILURE == php_mb_parse_encoding_array(order_ht, &list, &size)) { + RETURN_FALSE; + } + } else { + if (FAILURE == php_mb_parse_encoding_list(ZSTR_VAL(order_str), ZSTR_LEN(order_str), &list, &size, 0)) { + RETURN_FALSE; + } } if (size == 0) { diff --git a/ext/mbstring/mbstring.stub.php b/ext/mbstring/mbstring.stub.php index 85f9305cc0..5598aa8c12 100644 --- a/ext/mbstring/mbstring.stub.php +++ b/ext/mbstring/mbstring.stub.php @@ -8,7 +8,7 @@ function mb_http_input(string $type = UNKNOWN): array|string|false {} function mb_http_output(string $encoding = UNKNOWN): string|bool {} -function mb_detect_order($encoding = UNKNOWN): array|bool {} +function mb_detect_order(array|string $encoding = UNKNOWN): array|bool {} /** @param string|int $substchar */ function mb_substitute_character($substchar = UNKNOWN): string|int|bool {} diff --git a/ext/mbstring/mbstring_arginfo.h b/ext/mbstring/mbstring_arginfo.h index 73da9874d9..8d37ae1cbe 100644 --- a/ext/mbstring/mbstring_arginfo.h +++ b/ext/mbstring/mbstring_arginfo.h @@ -15,7 +15,7 @@ ZEND_END_ARG_INFO() #define arginfo_mb_http_output arginfo_mb_internal_encoding ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_detect_order, 0, 0, MAY_BE_ARRAY|MAY_BE_BOOL) - ZEND_ARG_INFO(0, encoding) + ZEND_ARG_TYPE_MASK(0, encoding, MAY_BE_ARRAY|MAY_BE_STRING) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_substitute_character, 0, 0, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL)