Skip to content

Commit

Permalink
[Yaml] added support for the end of document marker
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 29, 2010
1 parent 1cd5939 commit 04e621a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Symfony/Components/Yaml/Parser.php
Expand Up @@ -503,14 +503,25 @@ protected function cleanup($value)
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
$this->offset += $count;

// remove leading comments and/or ---
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\n))*#su', '', $value, -1, $count);
// remove leading comments
$trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
if ($count == 1) {
// items have been removed, update the offset
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
$value = $trimmedValue;
}

// remove start of the document marker (---)
$trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count);
if ($count == 1) {
// items have been removed, update the offset
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
$value = $trimmedValue;

// remove end of the document marker (...)
$value = preg_replace('#\.\.\.\s*$#s', '', $value);
}

return $value;
}
}
11 changes: 11 additions & 0 deletions tests/Symfony/Tests/Components/Yaml/ParserTest.php
Expand Up @@ -89,6 +89,17 @@ public function testTabsInYaml()
}
}

public function testEndOfTheDocumentMarker()
{
$yaml = <<<EOF
--- %YAML:1.0
foo
...
EOF;

$this->assertEquals('foo', $this->parser->parse($yaml));
}

public function testObjectsSupport()
{
$b = array('foo' => new B(), 'bar' => 1);
Expand Down

0 comments on commit 04e621a

Please sign in to comment.