bug #39764 [Config] fix handling float-like key attribute values (xabbuh)
This PR was merged into the 4.4 branch.
Discussion
----------
[Config] fix handling float-like key attribute values
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #36001
| License | MIT
| Doc PR |
Commits
-------
a2ad4fa8b3
fix handling float-like key attribute values
This commit is contained in:
commit
0211b9afe8
@ -237,6 +237,10 @@ class PrototypedArrayNode extends ArrayNode
|
||||
} elseif (isset($v[$this->keyAttribute])) {
|
||||
$k = $v[$this->keyAttribute];
|
||||
|
||||
if (\is_float($k)) {
|
||||
$k = var_export($k, true);
|
||||
}
|
||||
|
||||
// remove the key attribute when required
|
||||
if ($this->removeKeyAttribute) {
|
||||
unset($v[$this->keyAttribute]);
|
||||
|
@ -201,6 +201,32 @@ class NormalizationTest extends TestCase
|
||||
$this->assertNormalized($tree, $data, $data);
|
||||
}
|
||||
|
||||
public function testFloatLikeValueAsMapKeyAttribute()
|
||||
{
|
||||
$tree = (new TreeBuilder('root'))
|
||||
->getRootNode()
|
||||
->useAttributeAsKey('number')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('foo')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$this->assertNormalized($tree, [
|
||||
[
|
||||
'number' => 3.0,
|
||||
'foo' => 'bar',
|
||||
],
|
||||
], [
|
||||
'3.0' => [
|
||||
'foo' => 'bar',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
|
||||
{
|
||||
self::assertSame($normalized, $tree->normalize($denormalized));
|
||||
|
Reference in New Issue
Block a user