Skip to content

Commit 613bc42

Browse files
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 ------- 036e722 Fix Cache error while using anonymous class
2 parents 357fe5d + 036e722 commit 613bc42

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public function write(ClassMetadata $metadata)
7070
*/
7171
private function escapeClassName($class)
7272
{
73+
if (false !== strpos($class, '@')) {
74+
// anonymous class: replace all PSR6-reserved characters
75+
return str_replace(["\0", '\\', '/', '@', ':', '{', '}', '(', ')'], '.', $class);
76+
}
77+
7378
return str_replace('\\', '.', $class);
7479
}
7580
}

src/Symfony/Component/Validator/Tests/Mapping/Cache/Psr6CacheTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public function testNameCollision()
2323
$this->cache->write($metadata);
2424
$this->assertFalse($this->cache->has('Foo_Bar'));
2525
}
26+
27+
public function testNameWithInvalidChars()
28+
{
29+
$metadata = new ClassMetadata('class@anonymous/path/file');
30+
31+
$this->cache->write($metadata);
32+
$this->assertTrue($this->cache->has('class@anonymous/path/file'));
33+
}
2634
}

0 commit comments

Comments
 (0)