Skip to content

Commit 537f125

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: [Form] Remove unnecessary imports minor #58472 CS: clean some whitespaces/indentation (keradus) Fix newline harden test to not depend on the system's configured default timezone [Form] Support intl.use_exceptions/error_level in NumberToLocalizedStringTransformer [Doctrine][Messenger] Use common sequence name to get id from Oracle [ExpressionLanguage] Add missing test case for `Lexer` [FrameworkBundle] Fix passing request_stack to session.listener ensure session storages are opened in tests before destroying them [Serializer] Fix `ObjectNormalizer` gives warnings on normalizing with public static property [HttpKernel] Correctly merge `max-age`/`s-maxage` and `Expires` headers [Security][Validator] Check translations for Czech [Security] Fix serialized object representation in tests [DoctrineBridge] Fix risky test warnings [Serializer] Catch `NotNormalizableValueException` for variadic parameters
2 parents a0a2351 + 8be4215 commit 537f125

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

Normalizer/AbstractNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,16 @@ protected function instantiateObject(array &$data, string $class, array &$contex
352352

353353
$variadicParameters = [];
354354
foreach ($data[$key] as $parameterKey => $parameterData) {
355-
$variadicParameters[$parameterKey] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $attributeContext, $format);
355+
try {
356+
$variadicParameters[$parameterKey] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $attributeContext, $format);
357+
} catch (NotNormalizableValueException $exception) {
358+
if (!isset($context['not_normalizable_value_exceptions'])) {
359+
throw $exception;
360+
}
361+
362+
$context['not_normalizable_value_exceptions'][] = $exception;
363+
$params[$paramName] = $parameterData;
364+
}
356365
}
357366

358367
$params = array_merge(array_values($params), $variadicParameters);

Normalizer/ObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
182182

183183
if ($context['_read_attributes'] ?? true) {
184184
if (!isset(self::$isReadableCache[$class.$attribute])) {
185-
self::$isReadableCache[$class.$attribute] = (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute)) || $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
185+
self::$isReadableCache[$class.$attribute] = $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute) || (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute));
186186
}
187187

188188
return self::$isReadableCache[$class.$attribute];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
use Symfony\Component\Uid\Uuid;
15+
16+
class DummyWithVariadicParameter
17+
{
18+
public array $variadic;
19+
20+
public function __construct(Uuid ...$variadic)
21+
{
22+
$this->variadic = $variadic;
23+
}
24+
}

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,16 @@ public function testDenormalizeWithPropertyPath()
953953

954954
$this->assertEquals($expected, $obj);
955955
}
956+
957+
public function testObjectNormalizerWithAttributeLoaderAndObjectHasStaticProperty()
958+
{
959+
$class = new class {
960+
public static string $foo;
961+
};
962+
963+
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));
964+
$this->assertSame([], $normalizer->normalize($class));
965+
}
956966
}
957967

958968
class ProxyObjectDummy extends ObjectDummy

Tests/SerializerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumConstructor;
6565
use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumProperty;
6666
use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrNull;
67+
use Symfony\Component\Serializer\Tests\Fixtures\DummyWithVariadicParameter;
68+
use Symfony\Component\Serializer\Tests\Fixtures\DummyWithVariadicProperty;
6769
use Symfony\Component\Serializer\Tests\Fixtures\FalseBuiltInDummy;
6870
use Symfony\Component\Serializer\Tests\Fixtures\FooImplementationDummy;
6971
use Symfony\Component\Serializer\Tests\Fixtures\FooInterfaceDummyDenormalizer;
@@ -1660,6 +1662,19 @@ public function testPartialDenormalizationWithMissingConstructorTypes()
16601662

16611663
$this->assertSame($expected, $exceptionsAsArray);
16621664
}
1665+
1666+
public function testPartialDenormalizationWithInvalidVariadicParameter()
1667+
{
1668+
$json = '{"variadic": ["a random string"]}';
1669+
1670+
$serializer = new Serializer([new UidNormalizer(), new ObjectNormalizer()], ['json' => new JsonEncoder()]);
1671+
1672+
$this->expectException(PartialDenormalizationException::class);
1673+
1674+
$serializer->deserialize($json, DummyWithVariadicParameter::class, 'json', [
1675+
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
1676+
]);
1677+
}
16631678
}
16641679

16651680
class Model

0 commit comments

Comments
 (0)