[php-src] master: ext/tidy: Accept null for the $encoding of the repair functions
| From: | lacatoire via ndossche | Date: | Thu, 15 Oct 2026 16:40:57 +0000 |
| Subject: | [php-src] master: ext/tidy: Accept null for the $encoding of the repair functions | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142317@lists.php.net to get a copy of this message | ||
Author: lacatoire (lacatoire)
Committer: ndossche (ndossche)
Date: 2026-10-15T18:39:56+02:00
Commit: https://github.com/php/php-src/commit/48994f596fe74191168a4b7b8894168aadab996e
Raw diff: https://github.com/php/php-src/commit/48994f596fe74191168a4b7b8894168aadab996e.diff
ext/tidy: Accept null for the $encoding of the repair functions
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
628db3f3b5b.
Closes GH-24288.
Changed paths:
A ext/tidy/tests/tidy_repair_encoding_null.phpt
M NEWS
M ext/tidy/tidy.c
Diff:
diff --git a/NEWS b/NEWS
index e5ff8f8df4d8..3399de580f0f 100644
--- a/NEWS
+++ b/NEWS
@@ -78,6 +78,10 @@ PHP NEWS
. Fixed password_get_info() and password_needs_rehash() accepting malformed
bcrypt costs. (Ilia Alshanetsky)
+- Tidy:
+ . Fixed tidy_repair_string(), tidy_repair_file(), tidy::repairString() and
+ tidy::repairFile() rejecting null for $encoding. (lacatoire)
+
- Zip:
. Fixed use-after-free when re-entering ZipArchive during destruction or
a close warning, and rejected opening streams while closing. (jvoisin)
diff --git a/ext/tidy/tests/tidy_repair_encoding_null.phpt
b/ext/tidy/tests/tidy_repair_encoding_null.phpt
new file mode 100644
index 000000000000..e1948724df56
--- /dev/null
+++ b/ext/tidy/tests/tidy_repair_encoding_null.phpt
@@ -0,0 +1,28 @@
+--TEST--
+tidy_repair_string() / tidy_repair_file() accept null for $encoding, as declared
+--EXTENSIONS--
+tidy
+--FILE--
+<?php
+declare(strict_types=1);
+
+$file = __DIR__ . '/tidy_repair_encoding_null.html';
+file_put_contents($file, '<p>test');
+
+var_dump(strlen(tidy_repair_string('<p>test', null, null)) > 0);
+var_dump(strlen(tidy_repair_file($file, null, null)) > 0);
+var_dump(strlen(tidy::repairString('<p>test', null, null)) > 0);
+var_dump(strlen(tidy::repairFile($file, null, null)) > 0);
+
+var_dump(tidy_repair_string('<p>test', null, null) ===
tidy_repair_string('<p>test'));
+?>
+--CLEAN--
+<?php
+unlink(__DIR__ . '/tidy_repair_encoding_null.html');
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c
index 4b9d0cb5d1c7..48e635022328 100644
--- a/ext/tidy/tidy.c
+++ b/ext/tidy/tidy.c
@@ -352,7 +352,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
Z_PARAM_PATH_STR(arg1)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(config_ht, config_str)
- Z_PARAM_STRING(enc, enc_len)
+ Z_PARAM_STRING_OR_NULL(enc, enc_len)
Z_PARAM_BOOL(use_include_path)
ZEND_PARSE_PARAMETERS_END();
@@ -364,7 +364,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
Z_PARAM_STR(arg1)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(config_ht, config_str)
- Z_PARAM_STRING(enc, enc_len)
+ Z_PARAM_STRING_OR_NULL(enc, enc_len)
ZEND_PARSE_PARAMETERS_END();
data = arg1;