@@ -2693,7 +2693,9 @@ MBSTRING_API char *php_mb_convert_encoding_ex(const char *input, size_t length,
2693
2693
/* }}} */
2694
2694
2695
2695
/* {{{ MBSTRING_API char *php_mb_convert_encoding() */
2696
- MBSTRING_API char * php_mb_convert_encoding (const char * input , size_t length , const mbfl_encoding * to_encoding , const char * _from_encodings , size_t * output_len )
2696
+ MBSTRING_API char * php_mb_convert_encoding (const char * input , size_t length ,
2697
+ const mbfl_encoding * to_encoding , const char * _from_encodings ,
2698
+ const uint32_t _from_encodings_arg_num , size_t * output_len )
2697
2699
{
2698
2700
const mbfl_encoding * from_encoding ;
2699
2701
@@ -2724,7 +2726,9 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
2724
2726
from_encoding = & mbfl_encoding_pass ;
2725
2727
}
2726
2728
} else {
2727
- php_error_docref (NULL , E_WARNING , "Illegal character encoding specified" );
2729
+ zend_argument_value_error (_from_encodings_arg_num , "must provide at least one valid character encoding" );
2730
+ efree ((void * )list );
2731
+ return NULL ;
2728
2732
}
2729
2733
if (list != NULL ) {
2730
2734
efree ((void * )list );
@@ -2735,7 +2739,8 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
2735
2739
}
2736
2740
/* }}} */
2737
2741
2738
- MBSTRING_API HashTable * php_mb_convert_encoding_recursive (HashTable * input , const mbfl_encoding * to_encoding , const char * _from_encodings )
2742
+ MBSTRING_API HashTable * php_mb_convert_encoding_recursive (HashTable * input , const mbfl_encoding * to_encoding ,
2743
+ const char * _from_encodings , const uint32_t _from_encodings_arg_num )
2739
2744
{
2740
2745
HashTable * output , * chash ;
2741
2746
zend_long idx ;
@@ -2758,15 +2763,17 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
2758
2763
ZEND_HASH_FOREACH_KEY_VAL (input , idx , key , entry ) {
2759
2764
/* convert key */
2760
2765
if (key ) {
2761
- ckey = php_mb_convert_encoding (ZSTR_VAL (key ), ZSTR_LEN (key ), to_encoding , _from_encodings , & ckey_len );
2766
+ ckey = php_mb_convert_encoding (ZSTR_VAL (key ), ZSTR_LEN (key ), to_encoding , _from_encodings ,
2767
+ _from_encodings_arg_num , & ckey_len );
2762
2768
key = zend_string_init (ckey , ckey_len , 0 );
2763
2769
efree (ckey );
2764
2770
}
2765
2771
/* convert value */
2766
2772
ZEND_ASSERT (entry );
2767
2773
switch (Z_TYPE_P (entry )) {
2768
2774
case IS_STRING :
2769
- cval = php_mb_convert_encoding (Z_STRVAL_P (entry ), Z_STRLEN_P (entry ), to_encoding , _from_encodings , & cval_len );
2775
+ cval = php_mb_convert_encoding (Z_STRVAL_P (entry ), Z_STRLEN_P (entry ), to_encoding , _from_encodings ,
2776
+ _from_encodings_arg_num , & cval_len );
2770
2777
ZVAL_STRINGL (& entry_tmp , cval , cval_len );
2771
2778
efree (cval );
2772
2779
break ;
@@ -2778,7 +2785,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
2778
2785
ZVAL_COPY (& entry_tmp , entry );
2779
2786
break ;
2780
2787
case IS_ARRAY :
2781
- chash = php_mb_convert_encoding_recursive (Z_ARRVAL_P (entry ), to_encoding , _from_encodings );
2788
+ chash = php_mb_convert_encoding_recursive (Z_ARRVAL_P (entry ), to_encoding , _from_encodings ,
2789
+ _from_encodings_arg_num );
2782
2790
if (chash ) {
2783
2791
ZVAL_ARR (& entry_tmp , chash );
2784
2792
} else {
@@ -2817,6 +2825,7 @@ PHP_FUNCTION(mb_convert_encoding)
2817
2825
char * _from_encodings = NULL , * ret , * s_free = NULL ;
2818
2826
zend_string * to_encoding_name ;
2819
2827
const mbfl_encoding * to_encoding ;
2828
+ #define FROM_ENCODING_ARG_NUM 3
2820
2829
2821
2830
zval * hash_entry ;
2822
2831
HashTable * target_hash ;
@@ -2881,7 +2890,8 @@ PHP_FUNCTION(mb_convert_encoding)
2881
2890
2882
2891
if (Z_TYPE_P (input ) == IS_STRING ) {
2883
2892
/* new encoding */
2884
- ret = php_mb_convert_encoding (Z_STRVAL_P (input ), Z_STRLEN_P (input ), to_encoding , _from_encodings , & size );
2893
+ ret = php_mb_convert_encoding (Z_STRVAL_P (input ), Z_STRLEN_P (input ), to_encoding , _from_encodings ,
2894
+ FROM_ENCODING_ARG_NUM , & size );
2885
2895
if (ret != NULL ) {
2886
2896
// TODO: avoid reallocation ???
2887
2897
RETVAL_STRINGL (ret , size ); /* the string is already strdup()'ed */
@@ -2894,7 +2904,7 @@ PHP_FUNCTION(mb_convert_encoding)
2894
2904
}
2895
2905
} else {
2896
2906
HashTable * tmp ;
2897
- tmp = php_mb_convert_encoding_recursive (Z_ARRVAL_P (input ), to_encoding , _from_encodings );
2907
+ tmp = php_mb_convert_encoding_recursive (Z_ARRVAL_P (input ), to_encoding , _from_encodings , FROM_ENCODING_ARG_NUM );
2898
2908
RETURN_ARR (tmp );
2899
2909
}
2900
2910
0 commit comments