Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading