From 5a95f5b6a2dde540d797ce7d1a57745f36bfb9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 9 Mar 2018 14:08:18 +0100 Subject: [PATCH] Fix a BC break introduced by #1547 --- features/main/relation.feature | 9 ++++++--- src/Serializer/AbstractItemNormalizer.php | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/features/main/relation.feature b/features/main/relation.feature index a04a8a13f2e..c4590181364 100644 --- a/features/main/relation.feature +++ b/features/main/relation.feature @@ -513,7 +513,7 @@ Feature: Relations support """ @dropSchema - Scenario: Issue #1547 Passing wrong argument to a relation + Scenario: Passing an invalid IRI to a relation When I add "Content-Type" header equal to "application/ld+json" And I send a "POST" request to "/relation_embedders" with body: """ @@ -524,8 +524,11 @@ Feature: Relations support Then the response status code should be 400 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON node "hydra:description" should contain "Expected IRI or nested document" + And the JSON node "hydra:description" should contain "Invalid value provided (invalid IRI?)." + @wip + @dropSchema + Scenario: Passing an invalid type to a relation When I add "Content-Type" header equal to "application/ld+json" And I send a "POST" request to "/relation_embedders" with body: """ @@ -536,4 +539,4 @@ Feature: Relations support Then the response status code should be 400 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON node "hydra:description" should contain "Expected IRI or nested document" + And the JSON node "hydra:description" should contain "Invalid value provided (invalid IRI?)." diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index df7746ba03b..dd8a6b11517 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -160,6 +160,10 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu */ protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = []) { + if (!\is_string($attribute)) { + throw new InvalidArgumentException('Invalid value provided (invalid IRI?).'); + } + $propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $this->getFactoryOptions($context)); $type = $propertyMetadata->getType(); @@ -299,7 +303,7 @@ protected function denormalizeRelation(string $attributeName, PropertyMetadata $ if ( !$this->resourceClassResolver->isResourceClass($className) || - ($propertyMetadata->isWritableLink() && \is_array($value)) + $propertyMetadata->isWritableLink() ) { $context['resource_class'] = $className; $context['api_allow_update'] = true;