Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a46753

Browse files
michaelzangerlenicolas-grekas
authored andcommitted
[Serializer] fixed fix encoding of cache keys with anonymous classes
1 parent 77418e7 commit 3a46753

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemP
4444
public function getMetadataFor($value)
4545
{
4646
$class = $this->getClass($value);
47-
// Key cannot contain backslashes according to PSR-6
48-
$key = strtr($class, '\\', '_');
47+
$key = rawurlencode(strtr($class, '\\', '_'));
4948

5049
$item = $this->cacheItemPool->getItem($key);
5150
if ($item->isHit()) {

src/Symfony/Component/Serializer/Tests/Mapping/Factory/CacheMetadataFactoryTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,20 @@ public function testInvalidClassThrowsException()
6363

6464
$factory->getMetadataFor('Not\Exist');
6565
}
66+
67+
public function testAnonymousClass()
68+
{
69+
$anonymousObject = new class() {
70+
};
71+
72+
$metadata = new ClassMetadata(\get_class($anonymousObject));
73+
$decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
74+
$decorated
75+
->expects($this->once())
76+
->method('getMetadataFor')
77+
->willReturn($metadata);
78+
79+
$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
80+
$this->assertEquals($metadata, $factory->getMetadataFor($anonymousObject));
81+
}
6682
}

0 commit comments

Comments
 (0)