Skip to content

Commit

Permalink
Fix attaching indents to the correct parent.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schneider committed Dec 18, 2018
1 parent 4c9093e commit 7cc2c97
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Horde/Yaml/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ public function parse($line)

// We don't know the parent of the node so we have to
// find it
foreach ($this->_indentSort[$node->indent] as $n) {
foreach (array_reverse(array_keys($this->_indentSort[$node->indent])) as $key) {
$n = $this->_indentSort[$node->indent][$key];
if ($n->indent == $node->indent) {
$node->parent = $n->parent;
break;
Expand Down
45 changes: 44 additions & 1 deletion test/Horde/Yaml/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,56 @@ public function testComplexParse()
. " - Needs to be backed up\n"
. " - Needs to be normalized\n"
. " type: mysql\n";

$expected = array('databases' => array(array('name' => 'spartan',
'notes' => array('Needs to be backed up',
'Needs to be normalized'),
'type' => 'mysql')));
$actual = Horde_Yaml::load($yaml);
$this->assertEquals($expected, $actual);

$yaml = <<<YAML
authors:
-
name: Gunnar Wrobel
user: wrobel
email: p@rdus.de
active: true
role: lead
dependencies:
required:
php: ^5
pear:
pear.php.net/Console_Getopt: '*'
optional:
pear:
pecl.php.net/PECL: '*'
YAML;
$expected = array(
'authors' => array(
array(
'name' => 'Gunnar Wrobel',
'user' => 'wrobel',
'email' => 'p@rdus.de',
'active' => true,
'role' => 'lead',
)
),
'dependencies' => array(
'required' => array(
'php' => '^5',
'pear' => array(
'pear.php.net/Console_Getopt' => '*',
)
),
'optional' => array(
'pear' => array(
'pecl.php.net/PECL' => '*'
)
)
)
);
$actual = Horde_Yaml::load($yaml);
$this->assertEquals($expected, $actual);
}

public function testUnliteralizing()
Expand Down

0 comments on commit 7cc2c97

Please sign in to comment.