diff --git a/src/Media/AbstractMedia.php b/src/Media/AbstractMedia.php index 52e3a2113..afdae4e3b 100644 --- a/src/Media/AbstractMedia.php +++ b/src/Media/AbstractMedia.php @@ -148,22 +148,23 @@ public function enableSvgMediaLibraryPreview($response, $attachment) */ public function validateSvgOnUpload($response) { - if ($response['type'] === 'image/svg+xml' && \class_exists('SimpleXMLElement')) { - $path = $response['tmp_name']; + if ($response['type'] !== 'image/svg+xml' && !\class_exists('SimpleXMLElement')) { + return $response; + } - $svgContent = \file($path); - $svgContent = \implode(' ', $svgContent); + $path = $response['tmp_name'] ?? ''; - if (\file_exists($path)) { - if (!Helpers::isValidXml($svgContent)) { - return [ - 'size' => $response, - 'name' => $response['name'], - ]; - } - } + $svgContent = \file($path); + $svgContent = \implode(' ', $svgContent); + + if (!\file_exists($path) || Helpers::isValidXml($svgContent)) { + return $response; } - return $response; + + return [ + 'size' => $response, + 'name' => $response['name'], + ]; } /**