Commit 4f0f3c87 authored by sun's avatar sun Committed by gdd

Fixed missing type casting for configuration values.

parent 40cc21c8
......@@ -248,9 +248,7 @@ function config_array_to_xml($array, &$xml_object) {
}
}
else {
// @todo Cast to string must happen in DrupalConfig::set() already. But
// over there, $value may also be an array, so the result is "Array".
$xml_object->addChild($key, (string) $value);
$xml_object->addChild($key, $value);
}
}
}
......@@ -113,6 +113,9 @@ public function set($key, $value) {
// between keys, but not within keys.
$key = preg_replace('@[^a-zA-Z0-9_.-]@', '', $key);
// Type-cast value into a string.
$value = $this->castValue($value);
$parts = explode('.', $key);
if (count($parts) == 1) {
$this->data[$key] = $value;
......@@ -122,6 +125,29 @@ public function set($key, $value) {
}
}
public function castValue($value) {
if (is_scalar($value)) {
// Handle special case of FALSE, which should be '0' instead of ''.
if ($value === FALSE) {
$value = '0';
}
else {
$value = (string) $value;
}
}
else {
// Any non-scalar value must be an array.
if (!is_array($value)) {
$value = (array) $value;
}
// Recurse into any nested keys.
foreach ($value as $key => $nested_value) {
$value[$key] = $this->castValue($nested_value);
}
}
return $value;
}
/**
* Unsets value in this config object.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment