From 12852c2aea09284b4b76a62dc6ef26b1e03a3fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 26 Jan 2016 20:26:38 +0100 Subject: [PATCH] [Validator] PSR-6 cache: Avoid name collision --- .../Component/Validator/Mapping/Cache/Psr6Cache.php | 4 ++-- .../Validator/Tests/Mapping/Cache/Psr6CacheTest.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php b/src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php index 5c671220d2c11..ae7f1d18e12eb 100644 --- a/src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php +++ b/src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php @@ -67,7 +67,7 @@ public function write(ClassMetadata $metadata) } /** - * Replaces backslashes by underscores in a class name. + * Replaces backslashes by dots in a class name. * * @param string $class * @@ -75,6 +75,6 @@ public function write(ClassMetadata $metadata) */ private function escapeClassName($class) { - return strtr($class, '\\', '_'); + return strtr($class, '\\', '.'); } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Cache/Psr6CacheTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Cache/Psr6CacheTest.php index 9bdb898c7050b..c11dddbf6ff9d 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Cache/Psr6CacheTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Cache/Psr6CacheTest.php @@ -4,6 +4,7 @@ use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Validator\Mapping\Cache\Psr6Cache; +use Symfony\Component\Validator\Mapping\ClassMetadata; /** * @author Kévin Dunglas @@ -14,4 +15,12 @@ protected function setUp() { $this->cache = new Psr6Cache(new ArrayAdapter()); } + + public function testNameCollision() + { + $metadata = new ClassMetadata('Foo\\Bar'); + + $this->cache->write($metadata); + $this->assertFalse($this->cache->has('Foo_Bar')); + } }