Skip to content

Commit

Permalink
Merge branch '2.5' into 2.6
Browse files Browse the repository at this point in the history
* 2.5:
  [2.3] [HttpFoundation] [MimeTypeGuesser]
  Removed dead code and various cleaning
  [Console] Make it clear that the second argument is not about command options.
  Added the '-' character for spaceless on tag start and end to be consistent for block, if, set and for nodes
  [Yaml] fixed parse shortcut Key after unindented collection.
  [Console] fixed #10531
  Make the container considered non-fresh if the environment parameters are changed

Conflicts:
	src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
  • Loading branch information
fabpot committed Jan 25, 2015
2 parents 58fc9f7 + c76a567 commit 29557eb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Parser.php
Expand Up @@ -98,7 +98,6 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
$data[] = $parser->parse($this->getNextEmbedBlock(null, true), $exceptionOnInvalidType, $objectSupport, $objectForMap);
} else {
if (isset($values['leadspaces'])
&& ' ' == $values['leadspaces']
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches)
) {
// this is a compact notation element, add to next block and parse
Expand All @@ -108,7 +107,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =

$block = $values['value'];
if ($this->isNextLineIndented()) {
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + strlen($values['leadspaces']) + 1);
}

$data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap);
Expand Down Expand Up @@ -349,7 +348,14 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
$newIndent = $indentation;
}

$data = array(substr($this->currentLine, $newIndent));
$data = array();
if ($this->getCurrentLineIndentation() >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
} else {
$this->moveToPreviousLine();

return;
}

if ($inSequence && $oldLineIndentation === $newIndent && '-' === $data[0][0]) {
// the previous line contained a dash but no item content, this line is a sequence item with the same indentation
Expand All @@ -372,7 +378,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
}

if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) {
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
$this->moveToPreviousLine();
break;
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/Fixtures/unindentedCollections.yml
Expand Up @@ -60,3 +60,23 @@ yaml: |
foo: bar
php: |
array('collection' => array('key' => array('a', 'b', 'c'), 'foo' => 'bar'))
---
test: Shortcut Key after unindented collection
brief: >
Key/value after unindented collection
yaml: |
collection:
- key: foo
foo: bar
php: |
array('collection' => array(array('key' => 'foo', 'foo' => 'bar')))
---
test: Shortcut Key after unindented collection with custom spaces
brief: >
Key/value after unindented collection
yaml: |
collection:
- key: foo
foo: bar
php: |
array('collection' => array(array('key' => 'foo', 'foo' => 'bar')))
16 changes: 16 additions & 0 deletions Tests/ParserTest.php
Expand Up @@ -475,6 +475,22 @@ public function testUnindentedCollectionException()
-item2
-item3
EOF;

$this->parser->parse($yaml);
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testShortcutKeyUnindentedCollectionException()
{
$yaml = <<<EOF
collection:
- key: foo
foo: bar
EOF;

$this->parser->parse($yaml);
Expand Down

0 comments on commit 29557eb

Please sign in to comment.