From: Nikita Popov Date: Mon, 30 Mar 2020 14:13:36 +0000 (+0200) Subject: mb_check_encoding(): Make var a proper array|string arg X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b02b3539e7210957bf8394a730f641ff5d7f9498;p=php mb_check_encoding(): Make var a proper array|string arg --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 774e6adc7e..5f68fd4d12 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -4327,34 +4327,32 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str Check if the string is valid for the specified encoding */ PHP_FUNCTION(mb_check_encoding) { - zval *input = NULL; - zend_string *enc = NULL; + zend_string *input_str = NULL, *enc = NULL; + HashTable *input_ht = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zS", &input, &enc) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(0, 2) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_ARRAY_HT(input_str, input_ht) + Z_PARAM_STR(enc) + ZEND_PARSE_PARAMETERS_END(); - /* FIXME: Actually check all inputs, except $_FILES file content. */ - if (input == NULL) { - if (MBSTRG(illegalchars) == 0) { - RETURN_TRUE; + if (input_ht) { + if (!php_mb_check_encoding_recursive(input_ht, enc)) { + RETURN_FALSE; } - RETURN_FALSE; - } - - if (Z_TYPE_P(input) == IS_ARRAY) { - if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) { + RETURN_TRUE; + } else if (input_str) { + if (!php_mb_check_encoding(ZSTR_VAL(input_str), ZSTR_LEN(input_str), enc ? ZSTR_VAL(enc): NULL)) { RETURN_FALSE; } + RETURN_TRUE; } else { - if (!try_convert_to_string(input)) { - RETURN_THROWS(); - } - if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) { - RETURN_FALSE; + /* FIXME: Actually check all inputs, except $_FILES file content. */ + if (MBSTRG(illegalchars) == 0) { + RETURN_TRUE; } + RETURN_FALSE; } - RETURN_TRUE; } /* }}} */ diff --git a/ext/mbstring/mbstring.stub.php b/ext/mbstring/mbstring.stub.php index 0463f570f4..85f9305cc0 100644 --- a/ext/mbstring/mbstring.stub.php +++ b/ext/mbstring/mbstring.stub.php @@ -10,6 +10,7 @@ function mb_http_output(string $encoding = UNKNOWN): string|bool {} function mb_detect_order($encoding = UNKNOWN): array|bool {} +/** @param string|int $substchar */ function mb_substitute_character($substchar = UNKNOWN): string|int|bool {} function mb_preferred_mime_name(string $encoding): string|false {} @@ -78,7 +79,7 @@ function mb_send_mail(string $to, string $subject, string $message, $additional_ function mb_get_info(string $type = UNKNOWN): array|string|int|false {} -function mb_check_encoding($var = UNBEK, string $encoding = UNKNOWN): bool {} +function mb_check_encoding(array|string $var = UNKNOWN, string $encoding = UNKNOWN): bool {} function mb_scrub(string $str, string $encoding = UNKNOWN): string|false {} diff --git a/ext/mbstring/mbstring_arginfo.h b/ext/mbstring/mbstring_arginfo.h index f454cc91e8..73da9874d9 100644 --- a/ext/mbstring/mbstring_arginfo.h +++ b/ext/mbstring/mbstring_arginfo.h @@ -186,7 +186,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_get_info, 0, 0, MAY_BE_ARRAY| ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_check_encoding, 0, 0, _IS_BOOL, 0) - ZEND_ARG_INFO(0, var) + ZEND_ARG_TYPE_MASK(0, var, MAY_BE_ARRAY|MAY_BE_STRING) ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0) ZEND_END_ARG_INFO()