Issue #1807058 by sun: Fixed Config stores a NULL value as an array.

8.0.x
catch 2012-10-09 16:41:59 +01:00
parent fe77630a7c
commit c98eebe464
2 changed files with 10 additions and 3 deletions

View File

@ -270,13 +270,14 @@ class Config {
* Any non-scalar value that is not an array (aka objects) gets cast * Any non-scalar value that is not an array (aka objects) gets cast
* to an array. * to an array.
* *
* @param $value * @param mixed $value
* A value being saved into the configuration system. * A value being saved into the configuration system.
* @param $value *
* @return string
* The value cast to a string or array. * The value cast to a string or array.
*/ */
public function castValue($value) { public function castValue($value) {
if (is_scalar($value)) { if (is_scalar($value) || $value === NULL) {
// Handle special case of FALSE, which should be '0' instead of ''. // Handle special case of FALSE, which should be '0' instead of ''.
if ($value === FALSE) { if ($value === FALSE) {
$value = '0'; $value = '0';

View File

@ -84,6 +84,9 @@ class ConfigFileContentTest extends WebTestBase {
// Add a boolean true value. Should get cast to 1 // Add a boolean true value. Should get cast to 1
$config->set($true_key, TRUE); $config->set($true_key, TRUE);
// Add a null value. Should get cast to an empty string.
$config->set('null', NULL);
// Add an array with a nested boolean false that should get cast to 0. // Add an array with a nested boolean false that should get cast to 0.
$config->set($casting_array_key, $casting_array_value); $config->set($casting_array_key, $casting_array_value);
$config->save(); $config->save();
@ -119,6 +122,9 @@ class ConfigFileContentTest extends WebTestBase {
// Read true value // Read true value
$this->assertEqual($config->get($true_key), '1', format_string("Boolean TRUE value returned the string '1'.")); $this->assertEqual($config->get($true_key), '1', format_string("Boolean TRUE value returned the string '1'."));
// Read null value.
$this->assertIdentical($config->get('null'), '');
// Read false that had been nested in an array value // Read false that had been nested in an array value
$this->assertEqual($config->get($casting_array_false_value_key), '0', format_string("Nested boolean FALSE value returned the string '0'.")); $this->assertEqual($config->get($casting_array_false_value_key), '0', format_string("Nested boolean FALSE value returned the string '0'."));