Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-supported SVG HTML element to HTML Sanitiser #3257

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Utils/Sanitiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private function getPurifier(): HTMLPurifier
// Allow src tag in iframe for embed fields
$definition->addAttribute('iframe', 'src', 'Text');

// Create non supported elements
$this->createNonSupportedElements($definition, explode(',',$allowedTags));


$this->purifier = new \HTMLPurifier($purifierConfig);

return $this->purifier;
Expand All @@ -69,4 +73,14 @@ public function clean(string $html): string
{
return $this->getPurifier()->purify($html);
}

/**
* Handles the creation of non-supported HTML elements by HTMLPurifier out of the box
*/
private function createNonSupportedElements(\HTMLPurifier_HTMLDefinition $definition, array $allowedTags)
{
if (array_search('svg', $allowedTags)) {
$definition->addElement('svg', 'Block', 'Flow', 'Common');
}
}
}