Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fixed list handing when dealing with object maps #17711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed list handing when dealing with object maps
  • Loading branch information
johnknl committed Feb 6, 2016
commit 91df68215829c7366ae3be844197c68781c36657
8 changes: 7 additions & 1 deletion 8 src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,13 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
}

if ($objectForMap && !is_object($data)) {
$data = (object) $data;
if (is_array($data)) {
foreach (array_keys($data) as $index => $key) {
if ($index !== $key) {
return empty($data) ? null : (object) $data;
}
}
}
}

return empty($data) ? null : $data;
Expand Down
18 changes: 18 additions & 0 deletions 18 src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,24 @@ public function testObjectForMapIsAppliedAfterParsing()
$this->assertEquals($expected, $this->parser->parse("foo: bar\nbaz: foobar", false, false, true));
}

public function testWillObjectForMapOptionWillIgnoreArrays()
{
$yaml = <<<YAML
array:
- key: one
- key: two
YAML;

$actual = $this->parser->parse($yaml, true, false, true);
$this->assertInternalType('object', $actual);

$this->assertInternalType('array', $actual->array);
$this->assertInternalType('object', $actual->array[0]);
$this->assertInternalType('object', $actual->array[1]);
$this->assertSame('one', $actual->array[0]->key);
$this->assertSame('two', $actual->array[1]->key);
}

/**
* @dataProvider invalidDumpedObjectProvider
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.