Skip to content

Commit 520bd26

Browse files
committed
[Yaml] Fix the parsing of float keys
1 parent e2156d7 commit 520bd26

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
133133
throw $e;
134134
}
135135

136+
// Convert float keys to strings, to avoid being converted to integers by PHP
137+
if (is_float($key)) {
138+
$key = (string) $key;
139+
}
140+
136141
if ('<<' === $key) {
137142
if (isset($values['value']) && 0 === strpos($values['value'], '*')) {
138143
$isInPlace = substr($values['value'], 1);

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,24 @@ public function testYamlDirective()
685685
EOF;
686686
$this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
687687
}
688+
689+
public function testFloatKeys()
690+
{
691+
$yaml = <<<EOF
692+
foo:
693+
1.2: "bar"
694+
1.3: "baz"
695+
EOF;
696+
697+
$expected = array(
698+
'foo' => array(
699+
'1.2' => 'bar',
700+
'1.3' => 'baz',
701+
),
702+
);
703+
704+
$this->assertEquals($expected, $this->parser->parse($yaml));
705+
}
688706
}
689707

690708
class B

0 commit comments

Comments
 (0)