[Yaml] added support for the end of document marker
This commit is contained in:
parent
1cd5939e9a
commit
04e621a5cd
|
@ -503,14 +503,25 @@ class Parser
|
||||||
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
|
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
|
||||||
$this->offset += $count;
|
$this->offset += $count;
|
||||||
|
|
||||||
// remove leading comments and/or ---
|
// remove leading comments
|
||||||
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\n))*#su', '', $value, -1, $count);
|
$trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
|
||||||
if ($count == 1) {
|
if ($count == 1) {
|
||||||
// items have been removed, update the offset
|
// items have been removed, update the offset
|
||||||
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
||||||
$value = $trimmedValue;
|
$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;
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,17 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEndOfTheDocumentMarker()
|
||||||
|
{
|
||||||
|
$yaml = <<<EOF
|
||||||
|
--- %YAML:1.0
|
||||||
|
foo
|
||||||
|
...
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
$this->assertEquals('foo', $this->parser->parse($yaml));
|
||||||
|
}
|
||||||
|
|
||||||
public function testObjectsSupport()
|
public function testObjectsSupport()
|
||||||
{
|
{
|
||||||
$b = array('foo' => new B(), 'bar' => 1);
|
$b = array('foo' => new B(), 'bar' => 1);
|
||||||
|
|
Reference in New Issue