8000 fix handling float-like key attribute values · symfony/symfony@a2ad4fa · GitHub
[go: up one dir, main page]

Skip to content

Commit a2ad4fa

Browse files
committed
fix handling float-like key attribute values
1 parent 3ee310f commit a2ad4fa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ protected function normalizeValue($value)
237237
} elseif (isset($v[$this->keyAttribute])) {
238238
$k = $v[$this->keyAttribute];
239239

240+
if (\is_float($k)) {
241+
$k = var_export($k, true);
242+
}
243+
240244
// remove the key attribute when required
241245
if ($this->removeKeyAttribute) {
242246
unset($v[$this->keyAttribute]);

src/Symfony/Component/Config/Tests/Definition/NormalizationTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,32 @@ public function testAssociativeArrayPreserveKeys()
201201
$this->assertNormalized($tree, $data, $data);
202202
}
203203

204+
public function testFloatLikeValueAsMapKeyAttribute()
205+
{
206+
$tree = (new TreeBuilder('root'))
207+
->getRootNode()
208+
->useAttributeAsKey('number')
209+
->arrayPrototype()
210+
->children()
211+
->scalarNode('foo')->end()
212+
->end()
213+
->end()
214+
->end()
215+
->buildTree()
216+
;
217+
218+
$this->assertNormalized($tree, [
219+
[
220+
'number' => 3.0,
221+
'foo' => 'bar',
222+
],
223+
], [
224+
'3.0' => [
225+
'foo' => 'bar',
226+
],
227+
]);
228+
}
229+
204230
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
205231
{
206232
self::assertSame($normalized, $tree->normalize($denormalized));

0 commit comments

Comments
 (0)
0