Skip to content

Commit 1886b26

Browse files
committed
changes from feedback
1 parent 9ee4a06 commit 1886b26

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

ext/tidy/tests/tidy_error1.phpt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ $tidy = new tidy();
1313

1414
try {
1515
$tidy->parseString($buffer, $config);
16-
} catch (\Error $e) {
17-
echo $e->getMessage(), PHP_EOL;
16+
} catch (\ValueError $e) {
17+
echo get_class($e) . ": " . $e->getMessage(), PHP_EOL;
1818
}
1919

2020
$config = ['neither'];
@@ -32,8 +32,17 @@ try {
3232
echo $e->getMessage(), PHP_EOL;
3333
}
3434

35+
$config = ['doctype' => 'php', 0 => 'value2'];
36+
37+
try {
38+
var_dump($tidy->parseString($buffer, $config));
39+
} catch (\TypeError $e) {
40+
echo $e->getMessage(), PHP_EOL;
41+
}
42+
3543
?>
3644
--EXPECT--
3745
tidy::parseString(): Argument #2 ($config) Unknown Tidy configuration option "bogus"
3846
tidy::parseString(): Argument #2 ($config) must be of type array with keys as string
3947
tidy::parseString(): Argument #2 ($config) Attempting to set read-only option "doctype-mode"
48+
tidy::parseString(): Argument #2 ($config) must be of type array with keys as string

ext/tidy/tidy.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ static void tidy_doc_update_properties(PHPTidyObj *);
130130
static void tidy_add_node_default_properties(PHPTidyObj *);
131131
static void *php_tidy_get_opt_val(PHPTidyDoc *, TidyOption, TidyOptionType *);
132132
static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetypes);
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);
133+
static zend_result _php_tidy_set_tidy_opt(TidyDoc, const char *, zval *, uint32_t arg);
134+
static zend_result _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options, uint32_t arg);
135135
static PHP_INI_MH(php_tidy_set_clean_output);
136136
static void php_tidy_clean_output_start(const char *name, size_t name_len);
137137
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,7 +209,7 @@ static void php_tidy_load_config(TidyDoc doc, const char *path)
209209
}
210210
}
211211

212-
static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_string, const HashTable *ht_options, int arg)
212+
static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_string, const HashTable *ht_options, uint32_t arg)
213213
{
214214
if (ht_options) {
215215
return _php_tidy_apply_config_array(doc, ht_options, arg);
@@ -222,7 +222,7 @@ static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_str
222222
return SUCCESS;
223223
}
224224

225-
static int _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value, int arg)
225+
static zend_result _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value, uint32_t arg)
226226
{
227227
TidyOption opt = tidyGetOptionByName(doc, optname);
228228
zend_string *str, *tmp_str;
@@ -783,15 +783,16 @@ static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetyp
783783
tidy_create_node_object(return_value, obj->ptdoc, node);
784784
}
785785

786-
static int _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options, int arg)
786+
static zend_result _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options, uint32_t arg)
787787
{
788788
zval *opt_val;
789789
zend_string *opt_name;
790790

791791
if (!HT_IS_PACKED(ht_options)) {
792792
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht_options, opt_name, opt_val) {
793793
if (opt_name == NULL) {
794-
continue;
794+
zend_argument_type_error(arg, "must be of type array with keys as string");
795+
return FAILURE;
795796
}
796797
_php_tidy_set_tidy_opt(doc, ZSTR_VAL(opt_name), opt_val, arg);
797798
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)