From df942d8180c37fa6300af1a8a3705eaef55181c9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 30 Aug 2020 09:21:38 +0200 Subject: [PATCH 1/2] Fix CS --- Serializer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Serializer.php b/Serializer.php index 470e9ed00..d9ce4230a 100644 --- a/Serializer.php +++ b/Serializer.php @@ -86,7 +86,7 @@ public function __construct(array $normalizers = [], array $encoders = []) if (!($normalizer instanceof NormalizerInterface || $normalizer instanceof DenormalizerInterface)) { @trigger_error(sprintf('Passing normalizers ("%s") which do not implement either "%s" or "%s" has been deprecated since Symfony 4.2.', \get_class($normalizer), NormalizerInterface::class, DenormalizerInterface::class), E_USER_DEPRECATED); - // throw new \InvalidArgumentException(\sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), NormalizerInterface::class, DenormalizerInterface::class)); + // throw new \InvalidArgumentException(sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), NormalizerInterface::class, DenormalizerInterface::class)); } } $this->normalizers = $normalizers; @@ -106,7 +106,7 @@ public function __construct(array $normalizers = [], array $encoders = []) if (!($encoder instanceof EncoderInterface || $encoder instanceof DecoderInterface)) { @trigger_error(sprintf('Passing encoders ("%s") which do not implement either "%s" or "%s" has been deprecated since Symfony 4.2.', \get_class($encoder), EncoderInterface::class, DecoderInterface::class), E_USER_DEPRECATED); - // throw new \InvalidArgumentException(\sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), EncoderInterface::class, DecoderInterface::class)); + // throw new \InvalidArgumentException(sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), EncoderInterface::class, DecoderInterface::class)); } } $this->encoder = new ChainEncoder($realEncoders); From a3231c0a512bf3eac8950d39a8a8fb9720f0bcae Mon Sep 17 00:00:00 2001 From: Michael Zangerle Date: Tue, 25 Aug 2020 11:11:10 +0200 Subject: [PATCH 2/2] [Serializer] fixed fix encoding of cache keys with anonymous classes --- Mapping/Factory/CacheClassMetadataFactory.php | 3 +-- .../Mapping/Factory/CacheMetadataFactoryTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Mapping/Factory/CacheClassMetadataFactory.php b/Mapping/Factory/CacheClassMetadataFactory.php index 0b904c144..081917c68 100644 --- a/Mapping/Factory/CacheClassMetadataFactory.php +++ b/Mapping/Factory/CacheClassMetadataFactory.php @@ -44,8 +44,7 @@ public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemP public function getMetadataFor($value) { $class = $this->getClass($value); - // Key cannot contain backslashes according to PSR-6 - $key = strtr($class, '\\', '_'); + $key = rawurlencode(strtr($class, '\\', '_')); $item = $this->cacheItemPool->getItem($key); if ($item->isHit()) { diff --git a/Tests/Mapping/Factory/CacheMetadataFactoryTest.php b/Tests/Mapping/Factory/CacheMetadataFactoryTest.php index 723dc9b04..907311d43 100644 --- a/Tests/Mapping/Factory/CacheMetadataFactoryTest.php +++ b/Tests/Mapping/Factory/CacheMetadataFactoryTest.php @@ -63,4 +63,20 @@ public function testInvalidClassThrowsException() $factory->getMetadataFor('Not\Exist'); } + + public function testAnonymousClass() + { + $anonymousObject = new class() { + }; + + $metadata = new ClassMetadata(\get_class($anonymousObject)); + $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock(); + $decorated + ->expects($this->once()) + ->method('getMetadataFor') + ->willReturn($metadata); + + $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter()); + $this->assertEquals($metadata, $factory->getMetadataFor($anonymousObject)); + } }