Skip to content

Commit 8a2ce27

Browse files
committed
mb_detect_order(): Use proper array|string argument
1 parent 500230f commit 8a2ce27

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

ext/mbstring/mbstring.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,15 @@ PHP_FUNCTION(mb_http_output)
15301530
Sets the current detect_order or Return the current detect_order as a array */
15311531
PHP_FUNCTION(mb_detect_order)
15321532
{
1533-
zval *arg1 = NULL;
1533+
zend_string *order_str = NULL;
1534+
HashTable *order_ht = NULL;
15341535

1535-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg1) == FAILURE) {
1536-
RETURN_THROWS();
1537-
}
1536+
ZEND_PARSE_PARAMETERS_START(0, 1)
1537+
Z_PARAM_OPTIONAL
1538+
Z_PARAM_STR_OR_ARRAY_HT(order_str, order_ht)
1539+
ZEND_PARSE_PARAMETERS_END();
15381540

1539-
if (!arg1) {
1541+
if (!order_str && !order_ht) {
15401542
size_t i;
15411543
size_t n = MBSTRG(current_detect_order_list_size);
15421544
const mbfl_encoding **entry = MBSTRG(current_detect_order_list);
@@ -1546,22 +1548,16 @@ PHP_FUNCTION(mb_detect_order)
15461548
entry++;
15471549
}
15481550
} else {
1549-
const mbfl_encoding **list = NULL;
1550-
size_t size = 0;
1551-
switch (Z_TYPE_P(arg1)) {
1552-
case IS_ARRAY:
1553-
if (FAILURE == php_mb_parse_encoding_array(Z_ARRVAL_P(arg1), &list, &size)) {
1554-
RETURN_FALSE;
1555-
}
1556-
break;
1557-
default:
1558-
if (!try_convert_to_string(arg1)) {
1559-
RETURN_THROWS();
1560-
}
1561-
if (FAILURE == php_mb_parse_encoding_list(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), &list, &size, 0)) {
1562-
RETURN_FALSE;
1563-
}
1564-
break;
1551+
const mbfl_encoding **list;
1552+
size_t size;
1553+
if (order_ht) {
1554+
if (FAILURE == php_mb_parse_encoding_array(order_ht, &list, &size)) {
1555+
RETURN_FALSE;
1556+
}
1557+
} else {
1558+
if (FAILURE == php_mb_parse_encoding_list(ZSTR_VAL(order_str), ZSTR_LEN(order_str), &list, &size, 0)) {
1559+
RETURN_FALSE;
1560+
}
15651561
}
15661562

15671563
if (size == 0) {

ext/mbstring/mbstring.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function mb_http_input(string $type = UNKNOWN): array|string|false {}
88

99
function mb_http_output(string $encoding = UNKNOWN): string|bool {}
1010

11-
function mb_detect_order($encoding = UNKNOWN): array|bool {}
11+
function mb_detect_order(array|string $encoding = UNKNOWN): array|bool {}
1212

1313
/** @param string|int $substchar */
1414
function mb_substitute_character($substchar = UNKNOWN): string|int|bool {}

ext/mbstring/mbstring_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ZEND_END_ARG_INFO()
1515
#define arginfo_mb_http_output arginfo_mb_internal_encoding
1616

1717
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_detect_order, 0, 0, MAY_BE_ARRAY|MAY_BE_BOOL)
18-
ZEND_ARG_INFO(0, encoding)
18+
ZEND_ARG_TYPE_MASK(0, encoding, MAY_BE_ARRAY|MAY_BE_STRING)
1919
ZEND_END_ARG_INFO()
2020

2121
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_substitute_character, 0, 0, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL)

0 commit comments

Comments
 (0)