Last active
September 14, 2021 11:43
-
-
Save geldmacher/b7fc62df2e46834b2a35ee2634f9b2b7 to your computer and use it in GitHub Desktop.
TYPO3 Hotfix for missing "filterUnits" attribute in the new SvgSanitizer (https://github.com/darylldoyle/svg-sanitizer/pull/41)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Vendor\ExtensionName\SvgSanitizer; | |
use enshrined\svgSanitize\data\AllowedAttributes as OriginalAllowedAttributes; | |
/** | |
* Class AllowedAttributes | |
* @package Vendor\ExtensionName\SvgSanitizer | |
*/ | |
class AllowedAttributes extends OriginalAllowedAttributes | |
{ | |
/** | |
* getAttributes | |
* | |
* @return array | |
*/ | |
public static function getAttributes(): array | |
{ | |
$allowedAttributes = parent::getAttributes(); | |
$additionalAllowedAttributes = [ | |
'filterUnits' | |
]; | |
return array_merge($allowedAttributes, $additionalAllowedAttributes); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('TYPO3_MODE') or die(); | |
if (TYPO3_MODE === 'BE') { | |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Core\Resource\Security\SvgSanitizer::class] = [ | |
'className' => Vendor\ExtensionName\SvgSanitizer\SvgSanitizer::class | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Vendor\ExtensionName\SvgSanitizer; | |
use enshrined\svgSanitize\Sanitizer; | |
use TYPO3\CMS\Core\Resource\Security\SvgSanitizer as OriginalSvgSanitizer; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
/** | |
* SvgSanitizer | |
* @package Vendor\ExtensionName\SvgSanitizer | |
*/ | |
class SvgSanitizer extends OriginalSvgSanitizer | |
{ | |
/** | |
* @param string $svg | |
* | |
* @return string | |
* @throws \BadFunctionCallException | |
*/ | |
public function sanitizeContent(string $svg): string | |
{ | |
$sanitizer = new Sanitizer(); | |
/** @var AllowedAttributes $allowedAttributes */ | |
$allowedAttributes = GeneralUtility::makeInstance(AllowedAttributes::class); | |
$sanitizer->setAllowedAttrs($allowedAttributes); | |
$sanitizer->removeRemoteReferences(true); | |
return $sanitizer->sanitize($svg) ?: ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment