Fix Cache error while using anonymous class

This commit is contained in:
Emmanuel BORGES 2019-03-08 11:29:43 +01:00 committed by Nicolas Grekas
parent 357fe5d6c3
commit 036e72210d
2 changed files with 13 additions and 0 deletions

View File

@ -70,6 +70,11 @@ class Psr6Cache implements CacheInterface
*/
private function escapeClassName($class)
{
if (false !== strpos($class, '@')) {
// anonymous class: replace all PSR6-reserved characters
return str_replace(["\0", '\\', '/', '@', ':', '{', '}', '(', ')'], '.', $class);
}
return str_replace('\\', '.', $class);
}
}

View File

@ -23,4 +23,12 @@ class Psr6CacheTest extends AbstractCacheTest
$this->cache->write($metadata);
$this->assertFalse($this->cache->has('Foo_Bar'));
}
public function testNameWithInvalidChars()
{
$metadata = new ClassMetadata('class@anonymous/path/file');
$this->cache->write($metadata);
$this->assertTrue($this->cache->has('class@anonymous/path/file'));
}
}