Skip to content

[Serializer] Don't pass null to preg_match() #43062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

derrabus
Copy link
Member

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Part of #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.

@@ -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 (!\is_string($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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might exclude Stringable values, it might be better compare with null directly, don't you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't expect decoders to emit stringables. But agreed, let's keep the impact of the change low.

Signed-off-by: Alexander M. Turek <me@derrabus.de>
@derrabus derrabus force-pushed the bugfix/data-uri-preg-match-null branch from 03125e8 to 4e6ea37 Compare September 17, 2021 08:50
@nicolas-grekas
Copy link
Member

Thank you @derrabus.

@nicolas-grekas nicolas-grekas merged commit 4211c7f into symfony:4.4 Sep 17, 2021
@derrabus derrabus deleted the bugfix/data-uri-preg-match-null branch September 17, 2021 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants