]> granicus.if.org Git - php/commitdiff
mb_check_encoding(): Make var a proper array|string arg
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 14:13:36 +0000 (16:13 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 14:15:12 +0000 (16:15 +0200)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.stub.php
ext/mbstring/mbstring_arginfo.h

index 774e6adc7e494dd4a716943d00c4c62d23fa778e..5f68fd4d12e2acbfab36b2260f0044b589793bd6 100644 (file)
@@ -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;
 }
 /* }}} */
 
index 0463f570f447e60f8d6139b8d4e906b555d8d79e..85f9305cc00dc6e57ad4046a19b441a98515c2bb 100644 (file)
@@ -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 {}
 
index f454cc91e8ea9a3a963121ec4b74ee2e4a63811c..73da9874d9ba1070b240fd63fd764a30b25fed96 100644 (file)
@@ -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()