8000 bug #14711 [Serializer] AbstractNormalizer instantiateObject avoid `n… · symfony/symfony@c563bbc · GitHub
[go: up one dir, main page]

Skip to content

Commit c563bbc

Browse files
committed
bug #14711 [Serializer] AbstractNormalizer instantiateObject avoid null rejection (boekkooi)
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #14711). Discussion ---------- [Serializer] AbstractNormalizer instantiateObject avoid `null` rejection | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR fixes a bug in the AbstractNormalizer when denormalizing a array with a null argument. Commits ------- d546080 [Serializer] AbstractNormalizer::instantiateObject avoid `null` rejection
2 parents 58efb98 + d546080 commit c563bbc

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
5959
/**
6060
* Sets the {@link ClassMetadataFactoryInterface} to use.
6161
*
62-
* @param ClassMetadataFactoryInterface|null $classMetadataFactory
63-
* @param NameConverterInterface|null $nameConverter
62+
* @param ClassMetadataFactoryInterface|null $classMetadataFactory
63+
* @param NameConverterInterface|null $nameConverter
6464
*/
6565
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null)
6666
{
@@ -324,7 +324,7 @@ protected function instantiateObject(array $data, $class, array &$context, \Refl
324324

325325
$allowed = $allowedAttributes === false || in_array($paramName, $allowedAttributes);
326326
$ignored = in_array($paramName, $this->ignoredAttributes);
327-
if ($allowed && !$ignored && isset($data[$key])) {
327+
if ($allowed && !$ignored && array_key_exists($key, $data)) {
328328
$params[] = $data[$key];
329329
// don't run set for a parameter passed to the constructor
330330
unset($data[$key]);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ public function testConstructorDenormalize()
193193
$this->assertTrue($obj->isBaz());
194194
}
195195

196+
public function testConstructorDenormalizeWithNullArgument()
197+
{
198+
$obj = $this->normalizer->denormalize(
199+
array('foo' => 'foo', 'bar' => null, 'baz' => true),
200+
__NAMESPACE__.'\GetConstructorDummy', 'any');
201+
$this->assertEquals('foo', $obj->getFoo());
202+
$this->assertNull($obj->getBar());
203+
$this->assertTrue($obj->isBaz());
204+
}
205+
196206
public function testConstructorDenormalizeWithMissingOptionalArgument()
197207
{
198208
$obj = $this->normalizer->denormalize(

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ public function testConstructorDenormalize()
137137
$this->assertTrue($obj->isBaz());
138138
}
139139

140+
public function testConstructorDenormalizeWithNullArgument()
141+
{
142+
$obj = $this->normalizer->denormalize(
143+
array('foo' => 'foo', 'bar' => null, 'baz' => true),
144+
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
145+
$this->assertEquals('foo', $obj->getFoo());
146+
$this->assertNull($obj->bar);
147+
$this->assertTrue($obj->isBaz());
148+
}
149+
140150
public function testConstructorDenormalizeWithMissingOptionalArgument()
141151
{
142152
$obj = $this->normalizer->denormalize(

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ public function testConstructorDenormalize()
151151
$this->assertEquals('bar', $obj->getBar());
152152
}
153153

154+
public function testConstructorDenormalizeWithNullArgument()
155+
{
156+
$obj = $this->normalizer->denormalize(
157+
array('foo' => null, 'bar' => 'bar'),
158+
__NAMESPACE__.'\PropertyConstructorDummy', '
159+
any'
160+
);
161+
$this->assertNull($obj->getFoo());
162+
$this->assertEquals('bar', $obj->getBar());
163+
}
164+
154165
/**
155166
* @dataProvider provideCallbacks
156167
*/

0 commit comments

Comments
 (0)
0