Skip to content

Commit

Permalink
[Serializer] Don't pass null to preg_match()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <[email protected]>
  • Loading branch information
derrabus committed Sep 17, 2021
1 parent 85b67b8 commit a10b610
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Normalizer/DataUriNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
1 change: 1 addition & 0 deletions Tests/Normalizer/DataUriNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit a10b610

Please sign in to comment.