[php-src] master: Merge branch 'PHP-8.5'
| From: | Shivam Mathur | Date: | Sun, 13 Sep 2026 18:01:26 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141190@lists.php.net to get a copy of this message | ||
Author: Shivam Mathur (shivammathur)
Date: 2026-09-13T23:30:49+05:30
Commit: https://github.com/php/php-src/commit/e783539fe5824067bbcc8b9e09f04735b819aa96
Raw diff: https://github.com/php/php-src/commit/e783539fe5824067bbcc8b9e09f04735b819aa96.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
Avoid closing libxml output encoder twice (#23678)
Changed paths:
A ext/dom/tests/DOMDocument_saveHTMLFile_failed_output_encoding.phpt
M ext/libxml/libxml.c
Diff:
diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_failed_output_encoding.phpt
b/ext/dom/tests/DOMDocument_saveHTMLFile_failed_output_encoding.phpt
new file mode 100644
index 000000000000..05adefb973aa
--- /dev/null
+++ b/ext/dom/tests/DOMDocument_saveHTMLFile_failed_output_encoding.phpt
@@ -0,0 +1,31 @@
+--TEST--
+DOMDocument::saveHTMLFile() does not close the encoder twice when opening the output fails
+--EXTENSIONS--
+dom
+--FILE--
+<?php
+$filename = __DIR__ . '/missing-saveHTMLFile-directory/output.html';
+foreach (['UTF-8', 'ISO-8859-1', 'UTF-16'] as $encoding) {
+ $doc = new DOMDocument();
+ $doc->loadHTML('<html><head><meta http-equiv="Content-Type"
content="text/html;
charset=UTF-8"></head><body>value</body></html>');
+
$doc->getElementsByTagName('meta')->item(0)->setAttribute('content',
'text/html; charset=' . $encoding);
+ for ($i = 0; $i < 3; $i++) {
+ $result = @$doc->saveHTMLFile($filename);
+ var_dump($result === 0 || $result === false);
+ }
+ var_dump($doc->getElementsByTagName('body')->item(0)->textContent ===
'value');
+}
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index 42cd0ceb9711..361339a3466f 100644
--- a/ext/libxml/libxml.c
+++ b/ext/libxml/libxml.c
@@ -618,8 +618,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
return ret;
err:
- /* Similarly to __xmlOutputBufferCreateFilename we should also close the encoder on failure. */
+#if LIBXML_VERSION < 21404
+ /* As of libxml 2.14.4, libxml closes the encoder after this callback fails. */
xmlCharEncCloseFunc(encoder);
+#endif
return NULL;
}