-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Tidy config strenghtening #18751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tidy config strenghtening #18751
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall liking the changes, some nits and comments.
ext/tidy/tidy.c
Outdated
@@ -222,19 +222,23 @@ static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_str | |||
return SUCCESS; | |||
} | |||
|
|||
static int _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value) | |||
static int _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value, int arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value, int arg) | |
static zend_result _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value, uint32_t arg) |
ext/tidy/tidy.c
Outdated
@@ -209,10 +209,10 @@ static void php_tidy_load_config(TidyDoc doc, const char *path) | |||
} | |||
} | |||
|
|||
static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_string, const HashTable *ht_options) | |||
static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_string, const HashTable *ht_options, int arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_string, const HashTable *ht_options, int arg) | |
static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_string, const HashTable *ht_options, uint32_t arg) |
ext/tidy/tests/tidy_error1.phpt
Outdated
tidy::parseString(): Argument #2 ($config) Unknown Tidy configuration option "bogus" | ||
tidy::parseString(): Argument #2 ($config) must be of type array with keys as string | ||
tidy::parseString(): Argument #2 ($config) Attempting to set read-only option "doctype-mode" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test for the exception name too?
ext/tidy/tidy.c
Outdated
@@ -779,7 +783,7 @@ static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetyp | |||
tidy_create_node_object(return_value, obj->ptdoc, node); | |||
} | |||
|
|||
static int _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options) | |||
static int _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options, int arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options, int arg) | |
static zend_result _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht_options, uint32_t arg) |
ext/tidy/tidy.c
Outdated
if (opt_name == NULL) { | ||
continue; | ||
} | ||
_php_tidy_set_tidy_opt(doc, ZSTR_VAL(opt_name), opt_val); | ||
_php_tidy_set_tidy_opt(doc, ZSTR_VAL(opt_name), opt_val, arg); | ||
} ZEND_HASH_FOREACH_END(); | ||
return SUCCESS; | ||
} else { | ||
zend_argument_type_error(arg, "must be of type array with keys as string"); | ||
return FAILURE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An array which has the following structure:
$array = ['key1' => 'val1', 5 => 'val2', 'key3' => 'val3'];
would not emit an exception.
1886b26
to
4175508
Compare
The tidyOptIsReadOnly change may be worth backporting BTW. The reason is that deprecations eventually become build failures. |
Sure if @Girgias does not mind I just might even though no idea who is actually the maintainer :) |
We have a maintainer for this? 🤔 |
At first I thought it was either you (as you seem to like document oriented extensions) or Gina but yes indeed ... no one. |
using tidyOptGetCategory when possible. related phpGH-18751
I don't mind backporting this. And yes we don't have a designated maintainer for this, I have done a few fixes and refactoring here and there but nothing major. :) |
4175508
to
62181f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final minor nits but LGTM :)
ext/tidy/tests/tidy_error1.phpt
Outdated
try { | ||
$tidy->parseString($buffer, $config); | ||
} catch (\ValueError $e) { | ||
echo get_class($e) . ": " . $e->getMessage(), PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either consistent use of .
or ,
echo get_class($e) . ": " . $e->getMessage(), PHP_EOL; | |
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
ext/tidy/tests/tidy_error1.phpt
Outdated
try { | ||
$tidy->parseString($buffer, $config); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo $e->getMessage(), PHP_EOL; | |
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
ext/tidy/tests/tidy_error1.phpt
Outdated
try { | ||
var_dump($tidy->parseString($buffer, $config)); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo $e->getMessage(), PHP_EOL; | |
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
ext/tidy/tests/tidy_error1.phpt
Outdated
try { | ||
var_dump($tidy->parseString($buffer, $config)); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo $e->getMessage(), PHP_EOL; | |
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
No description provided.