Skip to content

Commit b02b353

Browse files
committed
mb_check_encoding(): Make var a proper array|string arg
1 parent 50d07ff commit b02b353

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

ext/mbstring/mbstring.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4327,34 +4327,32 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
43274327
Check if the string is valid for the specified encoding */
43284328
PHP_FUNCTION(mb_check_encoding)
43294329
{
4330-
zval *input = NULL;
4331-
zend_string *enc = NULL;
4330+
zend_string *input_str = NULL, *enc = NULL;
4331+
HashTable *input_ht = NULL;
43324332

4333-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zS", &input, &enc) == FAILURE) {
4334-
RETURN_THROWS();
4335-
}
4333+
ZEND_PARSE_PARAMETERS_START(0, 2)
4334+
Z_PARAM_OPTIONAL
4335+
Z_PARAM_STR_OR_ARRAY_HT(input_str, input_ht)
4336+
Z_PARAM_STR(enc)
4337+
ZEND_PARSE_PARAMETERS_END();
43364338

4337-
/* FIXME: Actually check all inputs, except $_FILES file content. */
4338-
if (input == NULL) {
4339-
if (MBSTRG(illegalchars) == 0) {
4340-
RETURN_TRUE;
4339+
if (input_ht) {
4340+
if (!php_mb_check_encoding_recursive(input_ht, enc)) {
4341+
RETURN_FALSE;
43414342
}
4342-
RETURN_FALSE;
4343-
}
4344-
4345-
if (Z_TYPE_P(input) == IS_ARRAY) {
4346-
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
4343+
RETURN_TRUE;
4344+
} else if (input_str) {
4345+
if (!php_mb_check_encoding(ZSTR_VAL(input_str), ZSTR_LEN(input_str), enc ? ZSTR_VAL(enc): NULL)) {
43474346
RETURN_FALSE;
43484347
}
4348+
RETURN_TRUE;
43494349
} else {
4350-
if (!try_convert_to_string(input)) {
4351-
RETURN_THROWS();
4352-
}
4353-
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
4354-
RETURN_FALSE;
4350+
/* FIXME: Actually check all inputs, except $_FILES file content. */
4351+
if (MBSTRG(illegalchars) == 0) {
4352+
RETURN_TRUE;
43554353
}
4354+
RETURN_FALSE;
43564355
}
4357-
RETURN_TRUE;
43584356
}
43594357
/* }}} */
43604358

ext/mbstring/mbstring.stub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function mb_http_output(string $encoding = UNKNOWN): string|bool {}
1010

1111
function mb_detect_order($encoding = UNKNOWN): array|bool {}
1212

13+
/** @param string|int $substchar */
1314
function mb_substitute_character($substchar = UNKNOWN): string|int|bool {}
1415

1516
function mb_preferred_mime_name(string $encoding): string|false {}
@@ -78,7 +79,7 @@ function mb_send_mail(string $to, string $subject, string $message, $additional_
7879

7980
function mb_get_info(string $type = UNKNOWN): array|string|int|false {}
8081

81-
function mb_check_encoding($var = UNBEK, string $encoding = UNKNOWN): bool {}
82+
function mb_check_encoding(array|string $var = UNKNOWN, string $encoding = UNKNOWN): bool {}
8283

8384
function mb_scrub(string $str, string $encoding = UNKNOWN): string|false {}
8485

ext/mbstring/mbstring_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_get_info, 0, 0, MAY_BE_ARRAY|
186186
ZEND_END_ARG_INFO()
187187

188188
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_check_encoding, 0, 0, _IS_BOOL, 0)
189-
ZEND_ARG_INFO(0, var)
189+
ZEND_ARG_TYPE_MASK(0, var, MAY_BE_ARRAY|MAY_BE_STRING)
190190
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
191191
ZEND_END_ARG_INFO()
192192

0 commit comments

Comments
 (0)