bug #10423 [Config] XmlUtils::convertDomElementToArray does not handle '0' (bendavies)

This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #10423).

Discussion
----------

[Config] XmlUtils::convertDomElementToArray does not handle '0'

`XmlUtils::convertDomElementToArray` does not handle `0` as a value of a text node, and interprets it as `null`.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | maybe? (if someone is depending on the previous behaviour.)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT

Commits
-------

e56ac59 convertDomElementToArray should handle zero values
This commit is contained in:
Fabien Potencier 2014-03-13 06:06:04 +01:00
commit 5368066a5a
2 changed files with 2 additions and 1 deletions

View File

@ -80,6 +80,7 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase
array(array('foo' => null), '<foo />'),
array(array('foo' => 'bar'), '<foo>bar</foo>'),
array(array('foo' => array('foo' => 'bar')), '<foo foo="bar"/>'),
array(array('foo' => array('foo' => 0)), '<foo><foo>0</foo></foo>'),
array(array('foo' => array('foo' => 'bar')), '<foo><foo>bar</foo></foo>'),
array(array('foo' => array('foo' => 'bar', 'value' => 'text')), '<foo foo="bar">text</foo>'),
array(array('foo' => array('attr' => 'bar', 'foo' => 'text')), '<foo attr="bar"><foo>text</foo></foo>'),

View File

@ -132,7 +132,7 @@ class XmlUtils
$nodeValue = false;
foreach ($element->childNodes as $node) {
if ($node instanceof \DOMText) {
if (trim($node->nodeValue)) {
if (strlen(trim($node->nodeValue)) > 0) {
$nodeValue = trim($node->nodeValue);
$empty = false;
}