Skip to content
Snippets Groups Projects
Commit c219ec8f authored by catch's avatar catch
Browse files

Issue #2498293 by cilefen, Fabianx: Only allow lowercase service and parameter names

parent fde95615
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -41,6 +41,9 @@ public function __construct(ParameterBagInterface $parameterBag = NULL) { ...@@ -41,6 +41,9 @@ public function __construct(ParameterBagInterface $parameterBag = NULL) {
* services in a frozen builder. * services in a frozen builder.
*/ */
public function set($id, $service, $scope = self::SCOPE_CONTAINER) { public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
}
SymfonyContainer::set($id, $service, $scope); SymfonyContainer::set($id, $service, $scope);
// Ensure that the _serviceId property is set on synthetic services as well. // Ensure that the _serviceId property is set on synthetic services as well.
...@@ -49,6 +52,26 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) { ...@@ -49,6 +52,26 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
} }
} }
/**
* {@inheritdoc}
*/
public function register($id, $class = null) {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
}
return parent::register($id, $class);
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value) {
if (strtolower($name) !== $name) {
throw new \InvalidArgumentException("Parameter names must be lowercase: $name");
}
parent::setParameter($name, $value);
}
/** /**
* Synchronizes a service change. * Synchronizes a service change.
* *
......
...@@ -977,7 +977,7 @@ protected function initializeRequestGlobals(Request $request) { ...@@ -977,7 +977,7 @@ protected function initializeRequestGlobals(Request $request) {
*/ */
protected function getServicesToPersist(ContainerInterface $container) { protected function getServicesToPersist(ContainerInterface $container) {
$persist = array(); $persist = array();
foreach ($container->getParameter('persistIds') as $id) { foreach ($container->getParameter('persist_ids') as $id) {
// It's pointless to persist services not yet initialized. // It's pointless to persist services not yet initialized.
if ($container->initialized($id)) { if ($container->initialized($id)) {
$persist[$id] = $container->get($id); $persist[$id] = $container->get($id);
...@@ -1127,7 +1127,7 @@ protected function compileContainer() { ...@@ -1127,7 +1127,7 @@ protected function compileContainer() {
$persist_ids[] = $id; $persist_ids[] = $id;
} }
} }
$container->setParameter('persistIds', $persist_ids); $container->setParameter('persist_ids', $persist_ids);
$container->compile(); $container->compile();
return $container; return $container;
......
...@@ -53,12 +53,12 @@ protected function setUp() { ...@@ -53,12 +53,12 @@ protected function setUp() {
*/ */
public function containerBuild(ContainerBuilder $container) { public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container); parent::containerBuild($container);
$container->register('DefaultConfigTest.schema_storage') $container->register('default_config_test.schema_storage')
->setClass('\Drupal\config_test\TestInstallStorage') ->setClass('\Drupal\config_test\TestInstallStorage')
->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY); ->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY);
$definition = $container->getDefinition('config.typed'); $definition = $container->getDefinition('config.typed');
$definition->replaceArgument(1, new Reference('DefaultConfigTest.schema_storage')); $definition->replaceArgument(1, new Reference('default_config_test.schema_storage'));
} }
/** /**
......
...@@ -15,7 +15,7 @@ form_test.route2: ...@@ -15,7 +15,7 @@ form_test.route2:
form_test.route3: form_test.route3:
path: '/form-test/object-service-builder' path: '/form-test/object-service-builder'
defaults: defaults:
_form: 'form_test.form.serviceForm' _form: 'form_test.form.serviceform'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
......
...@@ -38,4 +38,36 @@ public function testSet() { ...@@ -38,4 +38,36 @@ public function testSet() {
$this->assertEquals('bar', $class->_serviceId); $this->assertEquals('bar', $class->_serviceId);
} }
/**
* @covers ::set
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Service ID names must be lowercase: Bar
*/
public function testSetException() {
$container = new ContainerBuilder();
$class = new BarClass();
$container->set('Bar', $class);
$this->assertNotEquals('bar', $class->_serviceId);
}
/**
* @covers ::setParameter
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Parameter names must be lowercase: Buzz
*/
public function testSetParameterException() {
$container = new ContainerBuilder();
$container->setParameter('Buzz', 'buzz');
}
/**
* @covers ::register
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Service ID names must be lowercase: Bar
*/
public function testRegisterException() {
$container = new ContainerBuilder();
$container->register('Bar');
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment