Skip to content

Commit

Permalink
Fixes for nested elements when purifying
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Jan 19, 2025
1 parent 8de86a2 commit bfb771f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/Services/Pdf/Purify.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,25 @@ public static function clean(string $html): string

} else {
// First, remove ALL attributes from the node
while ($node->attributes->length > 0) {
$attr = $node->attributes->item(0);
$node->removeAttribute($attr->nodeName);
}
// while ($node->attributes->length > 0) {
// $attr = $node->attributes->item(0);
// $node->removeAttribute($attr->nodeName);
// }


if ($node instanceof \DOMElement) {
// Create a list of attributes to remove
$attributes_to_remove = [];
foreach ($node->attributes as $attr) {
$attributes_to_remove[] = $attr->nodeName;
}

// Remove the attributes
foreach ($attributes_to_remove as $attr_name) {
$node->removeAttribute($attr_name);
}
}

}

// Then add back only the allowed attributes
Expand Down

0 comments on commit bfb771f

Please sign in to comment.