Merge pull request #2075 from FathiBenNasr/fix/htmlutils-data-attributes

HtmlUtils: strip every data-* attribute, not just the first one
This commit is contained in:
Maarten 2026-10-22 12:28:44 +02:00 • committed by GitHub
commit 8a8304e81a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -160,13 +160,20 @@ abstract class HtmlUtils
// Remove all remaining data-* attributes // Remove all remaining data-* attributes
foreach ($xpath->query('//*[@*[starts-with(name(), "data-")]]') as $oElement) { foreach ($xpath->query('//*[@*[starts-with(name(), "data-")]]') as $oElement) {
$sTagNameLower = \strtolower($oElement->nodeName);
if ($oElement->hasAttributes()) { if ($oElement->hasAttributes()) {
// DOMNamedNodeMap is live: removing the attribute the foreach is
// currently on ends the iteration, so exactly one data-* was
// removed per element however many it carried. Collect the
// names first, then remove.
$aNames = [];
foreach ($oElement->attributes as $oAttr) { foreach ($oElement->attributes as $oAttr) {
if ('data-' === \substr(\strtolower($oAttr->nodeName), 0, 5)) { if ('data-' === \substr(\strtolower($oAttr->nodeName), 0, 5)) {
$oElement->removeAttribute($oAttr->nodeName); $aNames[] = $oAttr->nodeName;
} }
} }
foreach ($aNames as $sName) {
$oElement->removeAttribute($sName);
}
} }
} }