diff --git a/src/Symfony/Components/Yaml/Parser.php b/src/Symfony/Components/Yaml/Parser.php index 824a651f55d8..d6cbaf172d7b 100644 --- a/src/Symfony/Components/Yaml/Parser.php +++ b/src/Symfony/Components/Yaml/Parser.php @@ -65,7 +65,7 @@ public function parse($value) } $isRef = $isInPlace = $isProcessed = false; - if (preg_match('#^\-(\s+(?P.+?))?\s*$#', $this->currentLine, $values)) + if (preg_match('#^\-((?P\s+)(?P.+?))?\s*$#', $this->currentLine, $values)) { if (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#', $values['value'], $matches)) { @@ -87,13 +87,30 @@ public function parse($value) { $data[] = array($matches[1] => Inline::load($matches[2])); } + elseif (isset($values['leadspaces']) + && ' ' == $values['leadspaces'] + && preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P.+?))?\s*$#', $values['value'], $matches)) + { + // this is a compact notation element, add to next block and parse + $c = $this->getRealCurrentLineNb(); + $parser = new Parser($c); + $parser->refs =& $this->refs; + + $block = $values['value']; + if (!$this->isNextLineIndented()) + { + $block .= "\n".$this->getNextEmbedBlock(); + } + + $data[] = $parser->parse($block); + } else { $data[] = $this->parseValue($values['value']); } } } - else if (preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ ].*?) *\:(\s+(?P.+?))?\s*$#', $this->currentLine, $values)) + else if (preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P.+?))?\s*$#', $this->currentLine, $values)) { $key = Inline::parseScalar($values['key']); diff --git a/tests/fixtures/Symfony/Components/Yaml/YtsSpecificationExamples.yml b/tests/fixtures/Symfony/Components/Yaml/YtsSpecificationExamples.yml index c975fe5892f1..a1d300f00e7d 100644 --- a/tests/fixtures/Symfony/Components/Yaml/YtsSpecificationExamples.yml +++ b/tests/fixtures/Symfony/Components/Yaml/YtsSpecificationExamples.yml @@ -149,7 +149,7 @@ yaml: | hr: 63, avg: 0.288 } -ruby: | +php: | array( 'Mark McGwire' => array( 'hr' => 65, 'avg' => 0.278 ), @@ -286,7 +286,6 @@ syck: | --- test: Sequence key shortcut -todo: true spec: 2.12 yaml: | --- @@ -297,6 +296,21 @@ yaml: | quantity: 4 - item : Big Shoes quantity: 1 +php: | + array ( + array ( + 'item' => 'Super Hoop', + 'quantity' => 1, + ), + array ( + 'item' => 'Basketball', + 'quantity' => 4, + ), + array ( + 'item' => 'Big Shoes', + 'quantity' => 1, + ) + ) perl: | [ { item => 'Super Hoop', quantity => 1 },