Skip to content

Commit

Permalink
bug #37937 [Serializer] fixed fix encoding of cache keys with anonymo…
Browse files Browse the repository at this point in the history
…us 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
-------

3a4675359d [Serializer] fixed fix encoding of cache keys with anonymous classes
  • Loading branch information
nicolas-grekas committed Aug 31, 2020
2 parents df942d8 + a3231c0 commit f8e1211
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Mapping/Factory/CacheClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 16 additions & 0 deletions Tests/Mapping/Factory/CacheMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit f8e1211

Please sign in to comment.