Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 036e722

Browse filesBrowse files
Emmanuel BORGESnicolas-grekas
Emmanuel BORGES
authored andcommitted
Fix Cache error while using anonymous class
1 parent 357fe5d commit 036e722
Copy full SHA for 036e722

File tree

2 files changed

+13
-0
lines changed
Filter options

2 files changed

+13
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Mapping/Cache/Psr6CacheTest.php
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.