[php-src] Issue #12980: tidynode.props.attribute is missing "Boolean Attributes"
| From: | whitehorsesupport | Date: | Wed, 20 Dec 2023 05:09:20 +0000 |
| Subject: | [php-src] Issue #12980: tidynode.props.attribute is missing "Boolean Attributes" | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246077@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12980
Author: whitehorsesupport
### Description
The following code:
```php
<?php
$html = '<!DOCTYPE html><html
lang="en"><head><title>bug</title></head><body><select><option
selected
value="en">English</option></select></body></html>';
$tidy = new tidy();
$tidy->ParseString($html);
//echo "\n".tidy_get_output($tidy)."\n\n"; Uncomment this line to verify that
tidy is seeing the Boolean Attributes
function walk_nodes($node) {
if(!empty($node->attribute)){
echo '<'.$node->name.'>'."\n";
foreach($node->attribute as $attributeKey=>$attributeValue) {
echo ' ATTR
'.var_export($attributeKey,true).'=>'.var_export($attributeValue,true)."\n";
}
}
if($node->hasChildren()) {
foreach($node->child as $child) {
walk_nodes($child);
}
}
}
walk_nodes($tidy->root());
```
Resulted in this output:
```
<html>
ATTR 'lang'=>'en'
<option>
ATTR 'value'=>'en'
```
But I expected this output instead:
```
<html>
ATTR 'lang'=>'en'
<option>
ATTR 'selected'=>true
ATTR 'value'=>'en'
```
Documentation for tidynode.props.attribute, There isn't any mention about this and I believe it
is an unintended bug.
https://www.php.net/manual/en/class.tidynode.php#tidynode.props.attribute
The value of a "Boolean Attribute" is debatable. It could be NULL but I think it would be
better if it was true.(If NULL was desired the fix below would need to be tweaked.)
After reviewing the PHP source code I believe the issue is probably located here
https://github.com/php/php-src/blob/master/ext/tidy/tidy.c
on line 665
I would suggest that the fix look something like this starting on line 665 /ext/tidy/tidy.c
```
= if (name && val) {
= add_assoc_string(&attribute, name, val);
- }
+ } else if (name) {
+ add_assoc_string(&attribute, name, true);//I am not sure how a type "Boolean"
true is set here so it may need to be tweaked.
+ }
```
Feel free to use the above code in making a patch, I the author disclaim and release all copyright
to it.
### PHP Version
PHP 8.2.10
### Operating System
_No response_