8000 [Serializer] Harden the ObjectNormalizer by dunglas · Pull Request #17959 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Component\Serializer\Normalizer;

use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\CircularReferenceException;
use Symfony\Component\Serializer\Exception\LogicException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;

/**
* Base class for a normalizer dealing with objects.
Expand Down Expand Up @@ -172,7 +174,11 @@ public function denormalize($data, $class, $format = null, array $context = arra
$ignored = in_array($attribute, $this->ignoredAttributes);

if ($allowed && !$ignored) {
$this->setAttributeValue($object, $attribute, $value, $format, $context);
try {
$this->setAttributeValue($object, $attribute, $value, $format, $context);
} catch (InvalidArgumentException $e) {
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@ public function testMaxDepth()

$this->assertEquals($expected, $result);
}

/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testThrowUnexpectedValueException()
{
$this->normalizer->denormalize(array('foo' => 'bar'), ObjectTypeHinted::class);
}
}

class ObjectDummy
Expand Down Expand Up @@ -658,3 +666,10 @@ public static function getBaz()
return 'L';
}
}

class ObjectTypeHinted
{
public function setFoo(array $f)
{
}
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/Serializer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"doctrine/annotations": "~1.0",
"doctrine/cache": "~1.0"
},
"conflict": {
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4"
Copy link
Member

Choose a reason for hiding this comment

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

Then I would rather update the constraint in require-devto ~2.8,>=2.8.4|~3.0,>=3.0.4.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? The conflict line has the same effect and works in prod too.

},
"suggest": {
"psr/cache-implementation": "For using the metadata cache.",
"symfony/yaml": "For using the default YAML mapping loader.",
Expand Down
0