diff --git a/typo3/sysext/core/Classes/Resource/Security/SvgSanitizer.php b/typo3/sysext/core/Classes/Resource/Security/SvgSanitizer.php index 373ade783bf19a6ea8188bbafc76bb9f75651bb0..3cabcdbff524761141ea0ca447443a6645c3c89e 100644 --- a/typo3/sysext/core/Classes/Resource/Security/SvgSanitizer.php +++ b/typo3/sysext/core/Classes/Resource/Security/SvgSanitizer.php @@ -49,8 +49,13 @@ class SvgSanitizer */ public function sanitizeContent(string $svg): string { + // @todo: Simplify again when https://github.com/darylldoyle/svg-sanitizer/pull/90 is merged and released. + $previousXmlErrorHandling = libxml_use_internal_errors(true); $sanitizer = new Sanitizer(); $sanitizer->removeRemoteReferences(true); - return $sanitizer->sanitize($svg) ?: ''; + $sanitizedString = $sanitizer->sanitize($svg) ?: ''; + libxml_clear_errors(); + libxml_use_internal_errors($previousXmlErrorHandling); + return $sanitizedString; } } diff --git a/typo3/sysext/core/Tests/Functional/Resource/Security/SvgSanitizerTest.php b/typo3/sysext/core/Tests/Functional/Resource/Security/SvgSanitizerTest.php index 281e99f8d876925219fb32aeb3d86ee82a2d72d8..dfb13e26fa4103cdc4238c294e9bb05a2b122530 100644 --- a/typo3/sysext/core/Tests/Functional/Resource/Security/SvgSanitizerTest.php +++ b/typo3/sysext/core/Tests/Functional/Resource/Security/SvgSanitizerTest.php @@ -42,24 +42,24 @@ class SvgSanitizerTest extends FunctionalTestCase $data = []; foreach ($finder as $file) { $fileName = $file->getFilename(); - $data[$fileName] = ['DirtySVG/' . $fileName, 'CleanSVG/' . $fileName]; + $data[$fileName] = [ + $basePath . 'DirtySVG/' . $fileName, + $basePath . 'CleanSVG/' . $fileName, + ]; } return $data; } /** - * @param string $filePath - * @param string $sanitizedFilePath * @test * @dataProvider svgContentIsSanitizedDataProvider */ - public function svgContentIsSanitized($filePath, $sanitizedFilePath): void + public function svgContentIsSanitized(string $filePath, string $sanitizedFilePath): void { - $basePath = dirname(__FILE__, 2) . '/Fixtures/'; $sanitizer = new SvgSanitizer(); self::assertStringEqualsFile( - $basePath . $sanitizedFilePath, - $sanitizer->sanitizeContent(file_get_contents($basePath . $filePath)) + $sanitizedFilePath, + $sanitizer->sanitizeContent(file_get_contents($filePath)) ); } }