From: Nikita Popov Date: Mon, 30 Mar 2020 13:41:55 +0000 (+0200) Subject: mb_convert_encoding(): Make $input a proper array|string arg X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0d244227498b2b725db797eea832bda2092df1c8;p=php mb_convert_encoding(): Make $input a proper array|string arg --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 62c71b19ce..dd801a94c5 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2773,17 +2773,16 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons Returns converted string in desired encoding */ PHP_FUNCTION(mb_convert_encoding) { - zval *input; zend_string *to_encoding_name; - zend_string *from_encodings_str = NULL; - HashTable *from_encodings_ht = NULL; + zend_string *input_str, *from_encodings_str = NULL; + HashTable *input_ht, *from_encodings_ht = NULL; const mbfl_encoding *to_encoding; const mbfl_encoding **from_encodings; size_t num_from_encodings; zend_bool free_from_encodings; ZEND_PARSE_PARAMETERS_START(2, 3) - Z_PARAM_ZVAL(input) + Z_PARAM_STR_OR_ARRAY_HT(input_str, input_ht) Z_PARAM_STR(to_encoding_name) Z_PARAM_OPTIONAL Z_PARAM_STR_OR_ARRAY_HT(from_encodings_str, from_encodings_ht) @@ -2794,12 +2793,6 @@ PHP_FUNCTION(mb_convert_encoding) RETURN_FALSE; } - if (Z_TYPE_P(input) != IS_STRING && Z_TYPE_P(input) != IS_ARRAY) { - if (!try_convert_to_string(input)) { - RETURN_THROWS(); - } - } - if (from_encodings_ht) { if (php_mb_parse_encoding_array(from_encodings_ht, &from_encodings, &num_from_encodings, 0) == FAILURE) { RETURN_FALSE; @@ -2822,11 +2815,11 @@ PHP_FUNCTION(mb_convert_encoding) RETURN_FALSE; } - if (Z_TYPE_P(input) == IS_STRING) { + if (input_str) { /* new encoding */ size_t size; char *ret = php_mb_convert_encoding( - Z_STRVAL_P(input), Z_STRLEN_P(input), + ZSTR_VAL(input_str), ZSTR_LEN(input_str), to_encoding, from_encodings, num_from_encodings, &size); if (ret != NULL) { // TODO: avoid reallocation ??? @@ -2838,7 +2831,7 @@ PHP_FUNCTION(mb_convert_encoding) } else { HashTable *tmp; tmp = php_mb_convert_encoding_recursive( - Z_ARRVAL_P(input), to_encoding, from_encodings, num_from_encodings); + input_ht, to_encoding, from_encodings, num_from_encodings); RETVAL_ARR(tmp); } diff --git a/ext/mbstring/mbstring.stub.php b/ext/mbstring/mbstring.stub.php index 11eb631c86..99211be0e3 100644 --- a/ext/mbstring/mbstring.stub.php +++ b/ext/mbstring/mbstring.stub.php @@ -48,8 +48,7 @@ function mb_strwidth(string $str, string $encoding = UNKNOWN): int|false {} function mb_strimwidth(string $str, int $start, int $width, string $trimmarker = UNKNOWN, string $encoding = UNKNOWN): string|false {} -/** @param array|string $str */ -function mb_convert_encoding($str, string $to, array|string $from = UNKNOWN): array|string|false {} +function mb_convert_encoding(array|string $str, string $to, array|string $from = UNKNOWN): array|string|false {} function mb_convert_case(string $sourcestring, int $mode, ?string $encoding = null): string|false {} diff --git a/ext/mbstring/mbstring_arginfo.h b/ext/mbstring/mbstring_arginfo.h index 5752d93ffe..ff1da3c55e 100644 --- a/ext/mbstring/mbstring_arginfo.h +++ b/ext/mbstring/mbstring_arginfo.h @@ -104,7 +104,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strimwidth, 0, 3, MAY_BE_STRI ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_convert_encoding, 0, 2, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, str) + ZEND_ARG_TYPE_MASK(0, str, MAY_BE_ARRAY|MAY_BE_STRING) ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, from, MAY_BE_ARRAY|MAY_BE_STRING) ZEND_END_ARG_INFO()