[Yaml] fixed handling an empty value

This commit is contained in:
Pavel Volokitin 2013-04-12 15:29:40 +06:00
parent 12b7073607
commit 047212a439
2 changed files with 12 additions and 3 deletions

View File

@ -102,7 +102,7 @@ class Parser
$parser->refs =& $this->refs; $parser->refs =& $this->refs;
$block = $values['value']; $block = $values['value'];
if (!$this->isNextLineIndented()) { if ($this->isNextLineIndented()) {
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2); $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
} }
@ -174,7 +174,7 @@ class Parser
// hash // hash
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { } elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
// if next line is less indented or equal, then it means that the current value is null // if next line is less indented or equal, then it means that the current value is null
if ($this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) { if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) {
$data[$key] = null; $data[$key] = null;
} else { } else {
$c = $this->getRealCurrentLineNb() + 1; $c = $this->getRealCurrentLineNb() + 1;
@ -493,7 +493,7 @@ class Parser
} }
$ret = false; $ret = false;
if ($this->getCurrentLineIndentation() <= $currentIndentation) { if ($this->getCurrentLineIndentation() > $currentIndentation) {
$ret = true; $ret = true;
} }

View File

@ -492,6 +492,15 @@ yaml:
EOF EOF
); );
} }
public function testEmptyValue()
{
$input = <<<EOF
hash:
EOF;
$this->assertEquals(array('hash' => null), Yaml::parse($input));
}
} }
class B class B