From c97686656642ed49d162d71fd195118fabf02830 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 6 Apr 2019 16:33:16 +0200 Subject: [PATCH] [symfony/HttpKernel] Throws an error when the generated class name is invalid. --- src/Symfony/Component/HttpKernel/Kernel.php | 9 ++++++++- .../Component/HttpKernel/Tests/KernelTest.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 5cc15dbbf9b90..0dcdc717d9b22 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -442,14 +442,21 @@ protected function build(ContainerBuilder $container) /** * Gets the container class. * + * @throws \InvalidArgumentException If the generated classname is invalid + * * @return string The container class */ protected function getContainerClass() { $class = \get_class($this); $class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class; + $class = $this->name.str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container'; + + if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { + throw new \InvalidArgumentException(sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment)); + } - return $this->name.str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container'; + return $class; } /** diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 1b66de40ffaf6..5be4fc8d83585 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -64,6 +64,20 @@ public function testClone() $this->assertNull($clone->getContainer()); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The environment "test.env" contains invalid characters, it can only contain characters allowed in PHP class names. + */ + public function testClassNameValidityGetter() + { + // We check the classname that will be generated by using a $env that + // contains invalid characters. + $env = 'test.env'; + $kernel = new KernelForTest($env, false); + + $kernel->boot(); + } + public function testInitializeContainerClearsOldContainers() { $fs = new Filesystem(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy