Skip to content

Commit

Permalink
[Config] Fix array sort on normalization in edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
romainneutron committed Dec 24, 2015
1 parent 45a0060 commit eca41a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Expand Up @@ -75,14 +75,17 @@ protected function preNormalize($value)
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;
}

/**
Expand Down
Expand Up @@ -74,6 +74,10 @@ public function getPreNormalizationTests()
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'),
Expand Down

0 comments on commit eca41a8

Please sign in to comment.