Skip to content

Commit e783539

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Avoid closing libxml output encoder twice (#23678)
2 parents 2101993 + 2f0362e commit e783539

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
DOMDocument::saveHTMLFile() does not close the encoder twice when opening the output fails
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$filename = __DIR__ . '/missing-saveHTMLFile-directory/output.html';
8+
foreach (['UTF-8', 'ISO-8859-1', 'UTF-16'] as $encoding) {
9+
$doc = new DOMDocument();
10+
$doc->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>value</body></html>');
11+
$doc->getElementsByTagName('meta')->item(0)->setAttribute('content', 'text/html; charset=' . $encoding);
12+
for ($i = 0; $i < 3; $i++) {
13+
$result = @$doc->saveHTMLFile($filename);
14+
var_dump($result === 0 || $result === false);
15+
}
16+
var_dump($doc->getElementsByTagName('body')->item(0)->textContent === 'value');
17+
}
18+
?>
19+
--EXPECT--
20+
bool(true)
21+
bool(true)
22+
bool(true)
23+
bool(true)
24+
bool(true)
25+
bool(true)
26+
bool(true)
27+
bool(true)
28+
bool(true)
29+
bool(true)
30+
bool(true)
31+
bool(true)

ext/libxml/libxml.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
618618
return ret;
619619

620620
err:
621-
/* Similarly to __xmlOutputBufferCreateFilename we should also close the encoder on failure. */
621+
#if LIBXML_VERSION < 21404
622+
/* As of libxml 2.14.4, libxml closes the encoder after this callback fails. */
622623
xmlCharEncCloseFunc(encoder);
624+
#endif
623625
return NULL;
624626
}
625627

0 commit comments

Comments
 (0)