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:
commit
613bc421cd
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user