Skip to content

Commit ffb4ad3

Browse files
authored
fix(jsonld): mitigate #6465 (#6469)
1 parent dee6471 commit ffb4ad3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/Serializer/AbstractItemNormalizer.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
141141
// Never remove this, with `application/json` we don't use our AbstractCollectionNormalizer and we need
142142
// to remove the collection operation from our context or we'll introduce security issues
143143
if (isset($context['operation']) && $context['operation'] instanceof CollectionOperationInterface) {
144-
unset($context['operation_name']);
145-
unset($context['operation']);
146-
unset($context['iri']);
144+
unset($context['operation_name'], $context['operation'], $context['iri']);
147145
}
148146

149147
if ($this->resourceClassResolver->isResourceClass($resourceClass)) {
@@ -176,8 +174,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
176174
$data = parent::normalize($object, $format, $context);
177175

178176
$context['data'] = $data;
179-
unset($context['property_metadata']);
180-
unset($context['api_attribute']);
177+
unset($context['property_metadata'], $context['api_attribute']);
181178

182179
if ($emptyResourceAsIri && \is_array($data) && 0 === \count($data)) {
183180
$context['data'] = $iri;
@@ -761,6 +758,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
761758
unset(
762759
$context['resource_class'],
763760
$context['force_resource_class'],
761+
$context['uri_variables'],
764762
);
765763

766764
// Anonymous resources
@@ -791,8 +789,11 @@ protected function getAttributeValue(object $object, string $attribute, ?string
791789
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
792790
}
793791

794-
unset($context['resource_class']);
795-
unset($context['force_resource_class']);
792+
unset(
793+
$context['resource_class'],
794+
$context['force_resource_class'],
795+
$context['uri_variables']
796+
);
796797

797798
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
798799

@@ -850,8 +851,7 @@ protected function normalizeRelation(ApiProperty $propertyMetadata, ?object $rel
850851
$context['iri'] = $iri = $this->iriConverter->getIriFromResource(resource: $relatedObject, context: $context);
851852
$context['data'] = $iri;
852853
$context['object'] = $relatedObject;
853-
unset($context['property_metadata']);
854-
unset($context['api_attribute']);
854+
unset($context['property_metadata'], $context['api_attribute']);
855855

856856
if ($this->tagCollector) {
857857
$this->tagCollector->collect($context);
@@ -909,6 +909,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
909909
) {
910910
$resourceClass = $this->resourceClassResolver->getResourceClass(null, $className);
911911
$context['resource_class'] = $resourceClass;
912+
unset($context['uri_variables']);
912913

913914
return $this->denormalizeCollection($attribute, $propertyMetadata, $type, $resourceClass, $value, $format, $context);
914915
}
@@ -933,7 +934,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
933934
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
934935
}
935936

936-
unset($context['resource_class']);
937+
unset($context['resource_class'], $context['uri_variables']);
937938

938939
return $this->serializer->denormalize($value, $className.'[]', $format, $context);
939940
}
@@ -943,7 +944,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
943944
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
944945
}
945946

946-
unset($context['resource_class']);
947+
unset($context['resource_class'], $context['uri_variables']);
947948

948949
return $this->serializer->denormalize($value, $className, $format, $context);
949950
}

0 commit comments

Comments
 (0)