Skip to content

Commit 93459a9

Browse files
bug #37937 [Serializer] fixed fix encoding of cache keys with anonymous classes (michaelzangerle)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Serializer] fixed fix encoding of cache keys with anonymous classes | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #36589 | License | MIT | Doc PR | - Commits ------- 3a46753 [Serializer] fixed fix encoding of cache keys with anonymous classes
2 parents 6e59396 + 3a46753 commit 93459a9

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)