@@ -130,8 +130,8 @@ static void tidy_doc_update_properties(PHPTidyObj *);
130
130
static void tidy_add_node_default_properties (PHPTidyObj * );
131
131
static void * php_tidy_get_opt_val (PHPTidyDoc * , TidyOption , TidyOptionType * );
132
132
static void php_tidy_create_node (INTERNAL_FUNCTION_PARAMETERS , tidy_base_nodetypes );
133
- static int _php_tidy_set_tidy_opt (TidyDoc , const char * , zval * );
134
- static int _php_tidy_apply_config_array (TidyDoc doc , const HashTable * ht_options );
133
+ static int _php_tidy_set_tidy_opt (TidyDoc , const char * , zval * , int arg );
134
+ static int _php_tidy_apply_config_array (TidyDoc doc , const HashTable * ht_options , int arg );
135
135
static PHP_INI_MH (php_tidy_set_clean_output );
136
136
static void php_tidy_clean_output_start (const char * name , size_t name_len );
137
137
static php_output_handler * php_tidy_output_handler_init (const char * handler_name , size_t handler_name_len , size_t chunk_size , int flags );
@@ -209,10 +209,10 @@ static void php_tidy_load_config(TidyDoc doc, const char *path)
209
209
}
210
210
}
211
211
212
- static zend_result php_tidy_apply_config (TidyDoc doc , const zend_string * str_string , const HashTable * ht_options )
212
+ static zend_result php_tidy_apply_config (TidyDoc doc , const zend_string * str_string , const HashTable * ht_options , int arg )
213
213
{
214
214
if (ht_options ) {
215
- return _php_tidy_apply_config_array (doc , ht_options );
215
+ return _php_tidy_apply_config_array (doc , ht_options , arg );
216
216
} else if (str_string ) {
217
217
if (php_check_open_basedir (ZSTR_VAL (str_string ))) {
218
218
return FAILURE ;
@@ -222,19 +222,19 @@ static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_str
222
222
return SUCCESS ;
223
223
}
224
224
225
- static int _php_tidy_set_tidy_opt (TidyDoc doc , const char * optname , zval * value )
225
+ static int _php_tidy_set_tidy_opt (TidyDoc doc , const char * optname , zval * value , int arg )
226
226
{
227
227
TidyOption opt = tidyGetOptionByName (doc , optname );
228
228
zend_string * str , * tmp_str ;
229
229
zend_long lval ;
230
230
231
231
if (!opt ) {
232
- php_error_docref ( NULL , E_WARNING , "Unknown Tidy configuration option \"%s\"" , optname );
232
+ zend_argument_value_error ( arg , "Unknown Tidy configuration option \"%s\"" , optname );
233
233
return FAILURE ;
234
234
}
235
235
236
236
if (tidyOptIsReadOnly (opt )) {
237
- php_error_docref ( NULL , E_WARNING , "Attempting to set read-only option \"%s\"" , optname );
237
+ zend_argument_value_error ( arg , "Attempting to set read-only option \"%s\"" , optname );
238
238
return FAILURE ;
239
239
}
240
240
@@ -341,7 +341,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
341
341
342
342
TIDY_SET_DEFAULT_CONFIG (doc );
343
343
344
- if (php_tidy_apply_config (doc , config_str , config_ht ) != SUCCESS ) {
344
+ if (php_tidy_apply_config (doc , config_str , config_ht , 2 ) != SUCCESS ) {
345
345
RETVAL_FALSE ;
346
346
} else if (enc_len ) {
347
347
if (tidySetCharEncoding (doc , enc ) < 0 ) {
@@ -779,7 +779,7 @@ static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetyp
779
779
tidy_create_node_object (return_value , obj -> ptdoc , node );
780
780
}
781
781
782
- static int _php_tidy_apply_config_array (TidyDoc doc , const HashTable * ht_options )
782
+ static int _php_tidy_apply_config_array (TidyDoc doc , const HashTable * ht_options , int arg )
783
783
{
784
784
zval * opt_val ;
785
785
zend_string * opt_name ;
@@ -789,10 +789,13 @@ static int _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options
789
789
if (opt_name == NULL ) {
790
790
continue ;
791
791
}
792
- _php_tidy_set_tidy_opt (doc , ZSTR_VAL (opt_name ), opt_val );
792
+ _php_tidy_set_tidy_opt (doc , ZSTR_VAL (opt_name ), opt_val , arg );
793
793
} ZEND_HASH_FOREACH_END ();
794
+ return SUCCESS ;
795
+ } else {
796
+ zend_argument_type_error (arg , "must be of type array with keys as string" );
797
+ return FAILURE ;
794
798
}
795
- return SUCCESS ;
796
799
}
797
800
798
801
static int php_tidy_parse_string (PHPTidyObj * obj , const char * string , uint32_t len , const char * enc )
@@ -1014,7 +1017,7 @@ PHP_FUNCTION(tidy_parse_string)
1014
1017
object_init_ex (return_value , tidy_ce_doc );
1015
1018
obj = Z_TIDY_P (return_value );
1016
1019
1017
- if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) != SUCCESS
1020
+ if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) != SUCCESS
1018
1021
|| php_tidy_parse_string (obj , ZSTR_VAL (input ), (uint32_t )ZSTR_LEN (input ), enc ) != SUCCESS ) {
1019
1022
zval_ptr_dtor (return_value );
1020
1023
RETURN_FALSE ;
@@ -1082,7 +1085,7 @@ PHP_FUNCTION(tidy_parse_file)
1082
1085
object_init_ex (return_value , tidy_ce_doc );
1083
1086
obj = Z_TIDY_P (return_value );
1084
1087
1085
- if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) != SUCCESS
1088
+ if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) != SUCCESS
1086
1089
|| php_tidy_parse_string (obj , ZSTR_VAL (contents ), (uint32_t )ZSTR_LEN (contents ), enc ) != SUCCESS ) {
1087
1090
zval_ptr_dtor (return_value );
1088
1091
RETVAL_FALSE ;
@@ -1377,7 +1380,7 @@ PHP_METHOD(tidy, __construct)
1377
1380
1378
1381
zend_error_handling error_handling ;
1379
1382
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
1380
- if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) != SUCCESS ) {
1383
+ if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) != SUCCESS ) {
1381
1384
zend_restore_error_handling (& error_handling );
1382
1385
zend_string_release_ex (contents , 0 );
1383
1386
RETURN_THROWS ();
@@ -1421,7 +1424,7 @@ PHP_METHOD(tidy, parseFile)
1421
1424
RETURN_THROWS ();
1422
1425
}
1423
1426
1424
- RETVAL_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) == SUCCESS
1427
+ RETVAL_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) == SUCCESS
1425
1428
&& php_tidy_parse_string (obj , ZSTR_VAL (contents ), (uint32_t )ZSTR_LEN (contents ), enc ) == SUCCESS );
1426
1429
1427
1430
zend_string_release_ex (contents , 0 );
@@ -1450,7 +1453,7 @@ PHP_METHOD(tidy, parseString)
1450
1453
TIDY_SET_CONTEXT ;
1451
1454
obj = Z_TIDY_P (object );
1452
1455
1453
- RETURN_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) == SUCCESS
1456
+ RETURN_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) == SUCCESS
1454
1457
&& php_tidy_parse_string (obj , ZSTR_VAL (input ), (uint32_t )ZSTR_LEN (input ), enc ) == SUCCESS );
1455
1458
}
1456
1459
0 commit comments