Skip to content

ext/tidy: Accept null for the $encoding of the repair functions - #24288

Closed
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/tidy-repair-null-encoding
Closed

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/tidy-repair-null-encoding

Conversation

@lacatoire

@lacatoire lacatoire commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

tidy_repair_string(), tidy_repair_file(), tidy::repairString() and tidy::repairFile() declare ?string $encoding = null but parse it with Z_PARAM_STRING, so passing null is rejected. All other tidy entry points already use Z_PARAM_STRING_OR_NULL for this parameter (628db3f). null is then handled like an omitted argument: enc_len is 0 and the encoding is not set.

Before:

$ php -r 'declare(strict_types=1); tidy_repair_string("<p>test", null, null);'
Fatal error: Uncaught TypeError: tidy_repair_string(): Argument #3 ($encoding) must be of type string, null given

After:

$ sapi/cli/php -r 'declare(strict_types=1); var_dump(strlen(tidy_repair_string("<p>test", null, null)) > 0);'
bool(true)

$ sapi/cli/php run-tests.php ext/tidy
Tests passed    :    51 (98.1%)
Tests failed    :     0 (  0.0%)

The new test tidy_repair_encoding_null.phpt fails without the fix (the TypeError above) and passes with it.

php_tidy_quick_repair() parses $encoding with Z_PARAM_STRING while the
stubs of tidy_repair_string(), tidy_repair_file(), tidy::repairString()
and tidy::repairFile() declare ?string. Every other tidy entry point
taking this parameter already uses Z_PARAM_STRING_OR_NULL since
628db3f.
@ndossche ndossche closed this in 48994f5 Oct 15, 2026
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.

2 participants