diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 19899a5..8c9747a 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; +use Drupal\Component\Utility\String; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -215,6 +216,17 @@ public function save() { $this->data[$key] = $this->castValue($key, $value); } } + else { + // Minimal validation. Should not try to serialize resources or non-arrays. + foreach ($this->data as $key => $value) { + if (is_resource($value) || (!is_scalar($value) && !is_array($value))) { + throw new UnsupportedDataTypeConfigException(String::format('Invalid data type for config element @name:@key', array( + '@name' => $this->getName(), + '@key' => $key, + ))); + } + } + } $this->storage->write($this->name, $this->data); $this->isNew = FALSE; diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index 8aa292b..238cd8b 100644 --- a/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -149,7 +149,7 @@ protected function castValue($key, $value) { if ($value === NULL) { $value = NULL; } - elseif (is_scalar($value)) { + elseif (is_scalar($value) && !is_resource($value)) { try { $element = $this->getSchemaWrapper()->get($key); if ($element instanceof PrimitiveInterface) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php index 7576163..2375608 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Config\ConfigNameException; use Drupal\simpletest\DrupalUnitTestBase; use Drupal\Core\Config\FileStorage; +use Drupal\Core\Config\DatabaseStorage; use Drupal\Core\Config\UnsupportedDataTypeConfigException; /** @@ -192,10 +193,11 @@ function testNameValidation() { */ public function testDataTypes() { \Drupal::moduleHandler()->install(array('config_test')); - $storage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]); + //$storage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]); + $storage = new DatabaseStorage($this->container->get('database'), 'config'); $name = 'config_test.types'; $config = $this->container->get('config.factory')->get($name); - $original_content = file_get_contents($storage->getFilePath($name)); + $original_content = file_get_contents(drupal_get_path('module', 'config_test') . "/config/$name.yml"); $this->verbose('
' . $original_content . "\n" . var_export($storage->read($name), TRUE));
 
     // Verify variable data types are intact.
@@ -220,7 +222,7 @@ public function testDataTypes() {
     $this->assertIdentical($config->get(), $data);
     // Assert the data against the file storage.
     $this->assertIdentical($storage->read($name), $data);
-    $this->verbose('
' . file_get_contents($storage->getFilePath($name)) . var_export($storage->read($name), TRUE));
+    $this->verbose('
' . $name . var_export($storage->read($name), TRUE));
 
     // Set data using config::setData().
     $config->setData($data)->save();