8000 cast arrays to objects after parsing has finished · symfony/symfony@45eb77a · GitHub
[go: up one dir, main page]

Skip to content

Commit 45eb77a

Browse files
committed
cast arrays to objects after parsing has finished
Casting arrays to objects must happen after the complete YAML string has been parsed to avoid errors when parsing subsequent lines.
1 parent 5da874d commit 45eb77a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
240240
if ($isRef) {
241241
$this->refs[$isRef] = $data[$key];
242242
}
243-
244-
if ($objectForMap && !is_object($data)) {
245-
$data = (object) $data;
246-
}
247243
} else {
248244
// multiple documents are not supported
249245
if ('---' === $this->currentLine) {
@@ -307,6 +303,10 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
307303
mb_internal_encoding($mbEncoding);
308304
}
309305

306+
if ($objectForMap && !is_object($data)) {
307+
$data = (object) $data;
308+
}
309+
310310
return empty($data) ? null : $data;
311311
}
312312

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,15 @@ public function testObjectForMapEnabledWithInlineMapping()
460460
$this->assertEquals('cat', $result->fiz);
461461
}
462462

463+
public function testObjectForMapIsAppliedAfterParsing()
464+
{
465+
$expected = new \stdClass();
466+
$expected->foo = 'bar';
467+
$expected->baz = 'foobar';
468+
469+
$this->assertEquals($expected, $this->parser->parse("foo: bar\nbaz: foobar", false, false, true));
470+
}
471+
463472
/**
464473
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
465474
*/

0 commit comments

Comments
 (0)
0