Skip to content

Commit

Permalink
Merge branch '5.1' into 5.2
Browse files Browse the repository at this point in the history
* 5.1:
  Dont allow unserializing classes with a destructor
  Dont allow unserializing classes with a destructor - 4.4
  [Cache] fix possible collision when writing tmp file in filesystem adapter
  a colon followed by spaces exclusively separates mapping keys and values
  Contracts: Remove ellipsis
  fix handling float-like key attribute values
  Fix missing BCC recipients in SES bridge
  Dont allow unserializing classes with a destructor - 5.1
  • Loading branch information
nicolas-grekas committed Jan 12, 2021
2 parents df2cc63 + 065c1eb commit 3b03305
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Definition/PrototypedArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ protected function normalizeValue($value)
} 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]);
Expand Down
26 changes: 26 additions & 0 deletions Tests/Definition/NormalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,32 @@ public function testAssociativeArrayPreserveKeys()
$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));
Expand Down

0 comments on commit 3b03305

Please sign in to comment.