@@ -4217,19 +4217,11 @@ static inline int php_mb_check_encoding_impl(mbfl_buffer_converter *convd, const
4217
4217
}
4218
4218
4219
4219
4220
- MBSTRING_API int php_mb_check_encoding (const char * input , size_t length , const char * enc )
4220
+ MBSTRING_API int php_mb_check_encoding (
4221
+ const char * input , size_t length , const mbfl_encoding * encoding )
4221
4222
{
4222
- const mbfl_encoding * encoding = MBSTRG (current_internal_encoding );
4223
4223
mbfl_buffer_converter * convd ;
4224
4224
4225
- if (enc != NULL ) {
4226
- encoding = mbfl_name2encoding (enc );
4227
- if (!encoding || encoding == & mbfl_encoding_pass ) {
4228
- php_error_docref (NULL , E_WARNING , "Invalid encoding \"%s\"" , enc );
4229
- return 0 ;
4230
- }
4231
- }
4232
-
4233
4225
convd = php_mb_init_convd (encoding );
4234
4226
if (convd == NULL ) {
4235
4227
php_error_docref (NULL , E_WARNING , "Unable to create converter" );
@@ -4245,9 +4237,8 @@ MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const c
4245
4237
}
4246
4238
4247
4239
4248
- MBSTRING_API int php_mb_check_encoding_recursive (HashTable * vars , const zend_string * enc )
4240
+ static int php_mb_check_encoding_recursive (HashTable * vars , const mbfl_encoding * encoding )
4249
4241
{
4250
- const mbfl_encoding * encoding = MBSTRG (current_internal_encoding );
4251
4242
mbfl_buffer_converter * convd ;
4252
4243
zend_long idx ;
4253
4244
zend_string * key ;
@@ -4256,14 +4247,6 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
4256
4247
4257
4248
(void )(idx );
4258
4249
4259
- if (enc != NULL ) {
4260
- encoding = mbfl_name2encoding (ZSTR_VAL (enc ));
4261
- if (!encoding || encoding == & mbfl_encoding_pass ) {
4262
- php_error_docref (NULL , E_WARNING , "Invalid encoding \"%s\"" , ZSTR_VAL (enc ));
4263
- return 0 ;
4264
- }
4265
- }
4266
-
4267
4250
convd = php_mb_init_convd (encoding );
4268
4251
if (convd == NULL ) {
4269
4252
php_error_docref (NULL , E_WARNING , "Unable to create converter" );
@@ -4292,7 +4275,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
4292
4275
}
4293
4276
break ;
4294
4277
case IS_ARRAY :
4295
- if (!php_mb_check_encoding_recursive (Z_ARRVAL_P (entry ), enc )) {
4278
+ if (!php_mb_check_encoding_recursive (Z_ARRVAL_P (entry ), encoding )) {
4296
4279
valid = 0 ;
4297
4280
break ;
4298
4281
}
@@ -4321,20 +4304,29 @@ PHP_FUNCTION(mb_check_encoding)
4321
4304
{
4322
4305
zend_string * input_str = NULL , * enc = NULL ;
4323
4306
HashTable * input_ht = NULL ;
4307
+ const mbfl_encoding * encoding = MBSTRG (current_internal_encoding );
4324
4308
4325
4309
ZEND_PARSE_PARAMETERS_START (0 , 2 )
4326
4310
Z_PARAM_OPTIONAL
4327
4311
Z_PARAM_STR_OR_ARRAY_HT (input_str , input_ht )
4328
4312
Z_PARAM_STR (enc )
4329
4313
ZEND_PARSE_PARAMETERS_END ();
4330
4314
4315
+ if (enc != NULL) {
4316
+ encoding = mbfl_name2encoding (ZSTR_VAL (enc ));
4317
+ if (!encoding || encoding == & mbfl_encoding_pass ) {
4318
+ php_error_docref (NULL , E_WARNING , "Invalid encoding \"%s\"" , ZSTR_VAL (enc ));
4319
+ RETURN_FALSE ;
4320
+ }
4321
+ }
4322
+
4331
4323
if (input_ht ) {
4332
- if (!php_mb_check_encoding_recursive (input_ht , enc )) {
4324
+ if (!php_mb_check_encoding_recursive (input_ht , encoding )) {
4333
4325
RETURN_FALSE ;
4334
4326
}
4335
4327
RETURN_TRUE ;
4336
4328
} else if (input_str ) {
4337
- if (!php_mb_check_encoding (ZSTR_VAL (input_str ), ZSTR_LEN (input_str ), enc ? ZSTR_VAL ( enc ): NULL )) {
4329
+ if (!php_mb_check_encoding (ZSTR_VAL (input_str ), ZSTR_LEN (input_str ), encoding )) {
4338
4330
RETURN_FALSE ;
4339
4331
}
4340
4332
RETURN_TRUE ;
0 commit comments