@@ -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,14 +222,14 @@ 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
@@ -238,7 +238,7 @@ static int _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value)
238
238
#else
239
239
if (tidyOptIsReadOnly (opt )) {
240
240
#endif
241
- php_error_docref ( NULL , E_WARNING , "Attempting to set read-only option \"%s\"" , optname );
241
+ zend_argument_value_error ( arg , "Attempting to set read-only option \"%s\"" , optname );
242
242
return FAILURE ;
243
243
}
244
244
@@ -345,7 +345,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
345
345
346
346
TIDY_SET_DEFAULT_CONFIG (doc );
347
347
348
- if (php_tidy_apply_config (doc , config_str , config_ht ) != SUCCESS ) {
348
+ if (php_tidy_apply_config (doc , config_str , config_ht , 2 ) != SUCCESS ) {
349
349
RETVAL_FALSE ;
350
350
} else if (enc_len ) {
351
351
if (tidySetCharEncoding (doc , enc ) < 0 ) {
@@ -783,7 +783,7 @@ static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetyp
783
783
tidy_create_node_object (return_value , obj -> ptdoc , node );
784
784
}
785
785
786
- static int _php_tidy_apply_config_array (TidyDoc doc , const HashTable * ht_options )
786
+ static int _php_tidy_apply_config_array (TidyDoc doc , const HashTable * ht_options , int arg )
787
787
{
788
788
zval * opt_val ;
789
789
zend_string * opt_name ;
@@ -793,10 +793,13 @@ static int _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options
793
793
if (opt_name == NULL ) {
794
794
continue ;
795
795
}
796
- _php_tidy_set_tidy_opt (doc , ZSTR_VAL (opt_name ), opt_val );
796
+ _php_tidy_set_tidy_opt (doc , ZSTR_VAL (opt_name ), opt_val , arg );
797
797
} ZEND_HASH_FOREACH_END ();
798
+ return SUCCESS ;
799
+ } else {
800
+ zend_argument_type_error (arg , "must be of type array with keys as string" );
801
+ return FAILURE ;
798
802
}
799
- return SUCCESS ;
800
803
}
801
804
802
805
static int php_tidy_parse_string (PHPTidyObj * obj , const char * string , uint32_t len , const char * enc )
@@ -1018,7 +1021,7 @@ PHP_FUNCTION(tidy_parse_string)
1018
1021
object_init_ex (return_value , tidy_ce_doc );
1019
1022
obj = Z_TIDY_P (return_value );
1020
1023
1021
- if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) != SUCCESS
1024
+ if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) != SUCCESS
1022
1025
|| php_tidy_parse_string (obj , ZSTR_VAL (input ), (uint32_t )ZSTR_LEN (input ), enc ) != SUCCESS ) {
1023
1026
zval_ptr_dtor (return_value );
1024
1027
RETURN_FALSE ;
@@ -1086,7 +1089,7 @@ PHP_FUNCTION(tidy_parse_file)
1086
1089
object_init_ex (return_value , tidy_ce_doc );
1087
1090
obj = Z_TIDY_P (return_value );
1088
1091
1089
- if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) != SUCCESS
1092
+ if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) != SUCCESS
1090
1093
|| php_tidy_parse_string (obj , ZSTR_VAL (contents ), (uint32_t )ZSTR_LEN (contents ), enc ) != SUCCESS ) {
1091
1094
zval_ptr_dtor (return_value );
1092
1095
RETVAL_FALSE ;
@@ -1381,7 +1384,7 @@ PHP_METHOD(tidy, __construct)
1381
1384
1382
1385
zend_error_handling error_handling ;
1383
1386
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
1384
- if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) != SUCCESS ) {
1387
+ if (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) != SUCCESS ) {
1385
1388
zend_restore_error_handling (& error_handling );
1386
1389
zend_string_release_ex (contents , 0 );
1387
1390
RETURN_THROWS ();
@@ -1425,7 +1428,7 @@ PHP_METHOD(tidy, parseFile)
1425
1428
RETURN_THROWS ();
1426
1429
}
1427
1430
1428
- RETVAL_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) == SUCCESS
1431
+ RETVAL_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) == SUCCESS
1429
1432
&& php_tidy_parse_string (obj , ZSTR_VAL (contents ), (uint32_t )ZSTR_LEN (contents ), enc ) == SUCCESS );
1430
1433
1431
1434
zend_string_release_ex (contents , 0 );
@@ -1454,7 +1457,7 @@ PHP_METHOD(tidy, parseString)
1454
1457
TIDY_SET_CONTEXT ;
1455
1458
obj = Z_TIDY_P (object );
1456
1459
1457
- RETURN_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht ) == SUCCESS
1460
+ RETURN_BOOL (php_tidy_apply_config (obj -> ptdoc -> doc , options_str , options_ht , 2 ) == SUCCESS
1458
1461
&& php_tidy_parse_string (obj , ZSTR_VAL (input ), (uint32_t )ZSTR_LEN (input ), enc ) == SUCCESS );
1459
1462
}
1460
1463
0 commit comments