8000 Fix Cache error while using anonymous class by eborges78 · Pull Request #30487 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix Cache error while using anonymous class #30487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix Cache error while using anonymous class
  • Loading branch information
Emmanuel BORGES authored and nicolas-grekas committed Mar 15, 2019
commit 036e72210db356c4b16231660a94db04ae9de51c
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php
Original file line number Diff line number Diff line change
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);
}
}
Original file line number Diff line number Diff line change
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