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

Skip to content

Commit 53d286a

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

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-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_int($k) && !\is_string($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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,42 @@ 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+
$config = [
219+
[
220+
'number' => 3.0,
221+
'foo' => 'bar',
222+
],
223+
];
224+
$normalized = [
225+
'3.0' => [
226+
'foo' => 'bar',
227+
],
228+
];
229+
230+
$this->assertNormalized($tree, $config, $normalized);
231+
}
232+
233+
public function provideKeyAttributeValue(): array
234+
{
235+
return [
236+
[2.0],
237+
];
238+
}
239+
204240
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
205241
{
206242
self::assertSame($normalized, $tree->normalize($denormalized));

0 commit comments

Comments
 (0)
0