-
Couldn't load subscription status.
- Fork 8k
Closed as not planned
Closed as not planned
Copy link
Description
Description
\Dom\HTMLDocument::saveHtml()returns unintended=""(empty string) for boolean attribute values.\DOMDocument::saveHTML()returns the intended boolean attribute representations.
The following code: https://3v4l.org/eiOcP#v8.4.3
<?php
$TEST_HTML = '<html><body><input type="checkbox" checked></body></html>';
$domNew = Dom\HTMLDocument::createFromString($TEST_HTML, options: LIBXML_HTML_NOIMPLIED);
$domOld = new DOMDocument(encoding: 'UTF-8');
$domOld->loadHTML($TEST_HTML, options: LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
echo 'Dom\HTMLDocument::saveHtml():', "\n";
echo $domNew->saveHtml(), "\n";
echo "\n";
echo 'DOMDocument::saveHTML():', "\n";
echo $domOld->saveHTML(), "\n";Resulted in this output:
Dom\HTMLDocument::saveHtml():
<html><body><input type="checkbox" checked=""></body></html>
DOMDocument::saveHTML():
<html><body><input type="checkbox" checked></body></html>
But I expected this output instead:
Dom\HTMLDocument::saveHtml():
<html><body><input type="checkbox" checked></body></html>
DOMDocument::saveHTML():
<html><body><input type="checkbox" checked></body></html>
I read ./ext/dom/html5_serializer.c and libxml2/HTMLtree.c, I noticed that there is no if (attr->children != NULL) in ./ext/dom/html5_serializer.c::dom_html5_serialize_element_start().
(so ="" is always output...?)
I reported this issue as I was uncertain whether the above behavior was an intended design.
Thanks!
PHP Version
PHP 8.4.3
Operating System
Alpine 3.21, Windows 11