bug #30487 Fix Cache error while using anonymous class (Emmanuel BORGES)

This PR was merged into the 3.4 branch.

Discussion
----------

Fix Cache error while using anonymous class

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30395
| License       | MIT

Fix Cache error while using anonymous class

Commits
-------

036e72210d Fix Cache error while using anonymous class
This commit is contained in:
Nicolas Grekas 2019-03-15 14:35:18 +01:00
commit 613bc421cd
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'));
}
}