Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Jun 3, 2025

No description provided.

@devnexen devnexen marked this pull request as ready for review June 4, 2025 04:26
Copy link
Member

@Girgias Girgias left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Comment on lines 37 to 47
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"
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Comment on lines 793 to 803
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;
}
Copy link
Member

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.

@devnexen devnexen force-pushed the tidy_config_strenghtening branch 2 times, most recently from 1886b26 to 4175508 Compare June 4, 2025 17:36
@nielsdos
Copy link
Member

nielsdos commented Jun 4, 2025

The tidyOptIsReadOnly change may be worth backporting BTW. The reason is that deprecations eventually become build failures.

@devnexen
Copy link
Member Author

devnexen commented Jun 4, 2025

Sure if @Girgias does not mind I just might even though no idea who is actually the maintainer :)

@nielsdos
Copy link
Member

nielsdos commented Jun 4, 2025

who is actually the maintainer :)

We have a maintainer for this? 🤔

@devnexen
Copy link
Member Author

devnexen commented Jun 4, 2025

At first I thought it was either you (as you seem to like document oriented extensions) or Gina but yes indeed ... no one.

devnexen added a commit to devnexen/php-src that referenced this pull request Jun 4, 2025
using tidyOptGetCategory when possible.

related phpGH-18751
@Girgias
Copy link
Member

Girgias commented Jun 4, 2025

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. :)

devnexen added a commit that referenced this pull request Jun 4, 2025
using tidyOptGetCategory when possible.

related GH-18751

close GH-18763
@devnexen devnexen force-pushed the tidy_config_strenghtening branch from 4175508 to 62181f1 Compare June 4, 2025 19:40
Copy link
Member

@Girgias Girgias left a 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 :)

try {
$tidy->parseString($buffer, $config);
} catch (\ValueError $e) {
echo get_class($e) . ": " . $e->getMessage(), PHP_EOL;
Copy link
Member

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 ,

Suggested change
echo get_class($e) . ": " . $e->getMessage(), PHP_EOL;
echo $e::class, ": ", $e->getMessage(), PHP_EOL;

try {
$tidy->parseString($buffer, $config);
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $e->getMessage(), PHP_EOL;
echo $e::class, ": ", $e->getMessage(), PHP_EOL;

try {
var_dump($tidy->parseString($buffer, $config));
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $e->getMessage(), PHP_EOL;
echo $e::class, ": ", $e->getMessage(), PHP_EOL;

try {
var_dump($tidy->parseString($buffer, $config));
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $e->getMessage(), PHP_EOL;
echo $e::class, ": ", $e->getMessage(), PHP_EOL;

@devnexen devnexen closed this in 91becb3 Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants