Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ba1097c

Browse filesBrowse files
dbujewome62
authored andcommitted
[serializer] validate that the specified callbacks are actually callable
1 parent ecb52bc commit ba1097c
Copy full SHA for ba1097c

File tree

2 files changed

+9
-2
lines changed
Filter options

2 files changed

+9
-2
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
9999
$this->nameConverter = $nameConverter;
100100
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
101101

102-
if (\is_array($this->defaultContext[self::CALLBACKS] ?? null)) {
102+
if (\array_key_exists(self::CALLBACKS, $this->defaultContext)) {
103103
foreach ($this->defaultContext[self::CALLBACKS] as $attribute => $callback) {
104104
if (!\is_callable($callback)) {
105-
throw new InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute));
105+
throw new InvalidArgumentException(sprintf('The callback given in the default context for attribute "%s" is not callable.', $attribute));
106106
}
107107
}
108108
}

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public function normalize($object, $format = null, array $context = [])
8686
if (!isset($context['cache_key'])) {
8787
$context['cache_key'] = $this->getCacheKey($format, $context);
8888
}
89+
if (\array_key_exists(self::CALLBACKS, $context)) {
90+
foreach ($context[self::CALLBACKS] as $attribute => $callback) {
91+
if (!\is_callable($callback)) {
92+
throw new InvalidArgumentException(sprintf('The callback given in the context for attribute "%s" is not callable.', $attribute));
93+
}
94+
}
95+
}
8996

9097
if ($this->isCircularReference($object, $context)) {
9198
return $this->handleCircularReference($object, $format, $context);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.