[Yaml] Fix the parsing of float keys
This commit is contained in:
parent
e2156d7c2c
commit
520bd26642
@ -133,6 +133,11 @@ class Parser
|
|||||||
throw $e;
|
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 ('<<' === $key) {
|
||||||
if (isset($values['value']) && 0 === strpos($values['value'], '*')) {
|
if (isset($values['value']) && 0 === strpos($values['value'], '*')) {
|
||||||
$isInPlace = substr($values['value'], 1);
|
$isInPlace = substr($values['value'], 1);
|
||||||
|
@ -685,6 +685,24 @@ bar: 2
|
|||||||
EOF;
|
EOF;
|
||||||
$this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
|
$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
|
class B
|
||||||
|
Reference in New Issue
Block a user