Skip to content

Commit 4211c7f

Browse files
minor symfony#43062 [Serializer] Don't pass null to preg_match() (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] Don't pass `null` to `preg_match()` | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Part of symfony#41552 | License | MIT | Doc PR | N/A Calling `preg_match()` on `null` will trigger a deprecation error on PHP 8.1. This issue has been caught by our CI on the 5.4 branch. Commits ------- 4e6ea37 [Serializer] Don't pass null to preg_match()
2 parents 6fdf0c9 + 4e6ea37 commit 4211c7f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ public function supportsNormalization($data, $format = null)
109109
*/
110110
public function denormalize($data, $type, $format = null, array $context = [])
111111
{
112-
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)) {
112+
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)) {
113113
throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
114114
}
115115

116116
try {
117117
switch ($type) {
118-
case 'Symfony\Component\HttpFoundation\File\File':
118+
case File::class:
119119
return new File($data, false);
120120

121121
case 'SplFileObject':

src/Symfony/Component/Serializer/Tests/Normalizer/DataUriNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function invalidUriProvider()
139139
['data:text/html;charset,%3Ch1%3EHello!%3C%2Fh1%3E'],
140140
['data:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC'],
141141
[''],
142+
[null],
142143
['http://wikipedia.org'],
143144
['base64'],
144145
['iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC'],

0 commit comments

Comments
 (0)