Skip to content

Commit 6878324

Browse files
authored
Merge pull request #1762 from dunglas/bc-1547
Fix a BC break introduced by #1547
2 parents 0f33897 + 5a95f5b commit 6878324

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

features/main/relation.feature

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ Feature: Relations support
513513
"""
514514

515515
@dropSchema
516-
Scenario: Issue #1547 Passing wrong argument to a relation
516+
Scenario: Passing an invalid IRI to a relation
517517
When I add "Content-Type" header equal to "application/ld+json"
518518
And I send a "POST" request to "/relation_embedders" with body:
519519
"""
@@ -524,8 +524,11 @@ Feature: Relations support
524524
Then the response status code should be 400
525525
And the response should be in JSON
526526
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
527-
And the JSON node "hydra:description" should contain "Expected IRI or nested document"
527+
And the JSON node "hydra:description" should contain "Invalid value provided (invalid IRI?)."
528528

529+
@wip
530+
@dropSchema
531+
Scenario: Passing an invalid type to a relation
529532
When I add "Content-Type" header equal to "application/ld+json"
530533
And I send a "POST" request to "/relation_embedders" with body:
531534
"""
@@ -536,4 +539,4 @@ Feature: Relations support
536539
Then the response status code should be 400
537540
And the response should be in JSON
538541
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
539-
And the JSON node "hydra:description" should contain "Expected IRI or nested document"
542+
And the JSON node "hydra:description" should contain "Invalid value provided (invalid IRI?)."

src/Serializer/AbstractItemNormalizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
160160
*/
161161
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
162162
{
163+
if (!\is_string($attribute)) {
164+
throw new InvalidArgumentException('Invalid value provided (invalid IRI?).');
165+
}
166+
163167
$propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $this->getFactoryOptions($context));
164168
$type = $propertyMetadata->getType();
165169

@@ -299,7 +303,7 @@ protected function denormalizeRelation(string $attributeName, PropertyMetadata $
299303

300304
if (
301305
!$this->resourceClassResolver->isResourceClass($className) ||
302-
($propertyMetadata->isWritableLink() && \is_array($value))
306+
$propertyMetadata->isWritableLink()
303307
) {
304308
$context['resource_class'] = $className;
305309
$context['api_allow_update'] = true;

0 commit comments

Comments
 (0)