Skip to content

Commit

Permalink
Fix Cache error while using anonymous class
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel BORGES authored and nicolas-grekas committed Mar 15, 2019
1 parent 357fe5d commit 036e722
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php
Expand Up @@ -70,6 +70,11 @@ public function write(ClassMetadata $metadata)
*/
private function escapeClassName($class)
{
if (false !== strpos($class, '@')) {
// anonymous class: replace all PSR6-reserved characters
return str_replace(["\0", '\\', '/', '@', ':', '{', '}', '(', ')'], '.', $class);
}

return str_replace('\\', '.', $class);
}
}
Expand Up @@ -23,4 +23,12 @@ public function testNameCollision()
$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'));
}
}

0 comments on commit 036e722

Please sign in to comment.