From a10b610f75349dbee1d3ad05c7a2cbf4f1872e34 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 16 Sep 2021 15:31:58 +0200 Subject: [PATCH] [Serializer] Don't pass null to preg_match() Signed-off-by: Alexander M. Turek --- Normalizer/DataUriNormalizer.php | 4 ++-- Tests/Normalizer/DataUriNormalizerTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Normalizer/DataUriNormalizer.php b/Normalizer/DataUriNormalizer.php index b1643fb4d..e93724f8e 100644 --- a/Normalizer/DataUriNormalizer.php +++ b/Normalizer/DataUriNormalizer.php @@ -109,13 +109,13 @@ public function supportsNormalization($data, $format = null) */ public function denormalize($data, $type, $format = null, array $context = []) { - if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) { + if (null === $data || !preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) { throw new NotNormalizableValueException('The provided "data:" URI is not valid.'); } try { switch ($type) { - case 'Symfony\Component\HttpFoundation\File\File': + case File::class: return new File($data, false); case 'SplFileObject': diff --git a/Tests/Normalizer/DataUriNormalizerTest.php b/Tests/Normalizer/DataUriNormalizerTest.php index 24c5672be..02bd050bd 100644 --- a/Tests/Normalizer/DataUriNormalizerTest.php +++ b/Tests/Normalizer/DataUriNormalizerTest.php @@ -139,6 +139,7 @@ public function invalidUriProvider() ['data:text/html;charset,%3Ch1%3EHello!%3C%2Fh1%3E'], ['data:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC'], [''], + [null], ['http://wikipedia.org'], ['base64'], ['iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC'],