Some unexpected behaviour occurs if an attribute is specified more than once.
$html = str_get_html('<div id="test" style="display:none;" style="margin-top:5px;"></div>');
print_r($html->find("#test")[0]->getAllAttributes());
Array
(
[id] => test
[style] => display:none;
["margin-top:5px;"] => 1
)
Its even more unexpected if there is a space after the colon inside the style tag.
$html = str_get_html('<div id="test" style="display:none;" style="margin-top: 5px;"></div>');
print_r($html->find("#test")[0]->getAllAttributes());
Array
(
[id] => test
[style] => display:none;
["margin-top:] => 1
[5px;"] => 1
)
Some info: https://stackoverflow.com/questions/26341507/can-an-html-element-have-the-same-attribute-twice
It seems browser usually drop the duplicate attributes so it might be worth doing the same here?
Edit: I am using latest version 1.8.1
Another scenario where it can overwrite an unrelated attribute
Thanks for reporting this issue. You are right, duplicate attributes are only partially skipped (based on the attribute name) which causes the next character being parsed as if it was a new attribute. I've just pushed a fix in [a4b54c] which parses the entire attribute before dropping it. Let me know if it works for you.
Related
Commit: [a4b54c]
Hello, just wanted to confirm the fix has resolved the issue. Thank you!
Thanks for the feedback!