[Yaml] Fix the parsing of float keys

This commit is contained in:
Jose Gonzalez 2015-09-12 16:58:59 +01:00
parent e2156d7c2c
commit 520bd26642
2 changed files with 23 additions and 0 deletions

View File

@ -133,6 +133,11 @@ class Parser
throw $e;
}
// Convert float keys to strings, to avoid being converted to integers by PHP
if (is_float($key)) {
$key = (string) $key;
}
if ('<<' === $key) {
if (isset($values['value']) && 0 === strpos($values['value'], '*')) {
$isInPlace = substr($values['value'], 1);

View File

@ -685,6 +685,24 @@ bar: 2
EOF;
$this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
}
public function testFloatKeys()
{
$yaml = <<<EOF
foo:
1.2: "bar"
1.3: "baz"
EOF;
$expected = array(
'foo' => array(
'1.2' => 'bar',
'1.3' => 'baz',
),
);
$this->assertEquals($expected, $this->parser->parse($yaml));
}
}
class B