bug #17129 [Config] Fix array sort on normalization in edge case (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[Config] Fix array sort on normalization in edge case

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Commits
-------

eca41a8 [Config] Fix array sort on normalization in edge case
This commit is contained in:
Fabien Potencier 2015-12-26 13:02:10 +01:00
commit f24690e493
2 changed files with 10 additions and 3 deletions

View File

@ -75,14 +75,17 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
return $value;
}
$normalized = array();
foreach ($value as $k => $v) {
if (false !== strpos($k, '-') && false === strpos($k, '_') && !array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
$value[$normalizedKey] = $v;
unset($value[$k]);
$normalized[$normalizedKey] = $v;
} else {
$normalized[$k] = $v;
}
}
return $value;
return $normalized;
}
/**

View File

@ -74,6 +74,10 @@ class ArrayNodeTest extends \PHPUnit_Framework_TestCase
array('foo-bar_moo' => 'foo'),
array('foo-bar_moo' => 'foo'),
),
array(
array('anything-with-dash-and-no-underscore' => 'first', 'no_dash' => 'second'),
array('anything_with_dash_and_no_underscore' => 'first', 'no_dash' => 'second'),
),
array(
array('foo-bar' => null, 'foo_bar' => 'foo'),
array('foo-bar' => null, 'foo_bar' => 'foo'),