[Yaml] fixed offset when the document use --- or the %YAML element (patch from redotheoffice)

This commit is contained in:
Fabien Potencier 2010-02-23 11:52:41 +01:00
parent 46c4f23496
commit 83023764b6
4 changed files with 24 additions and 6 deletions

View File

@ -547,10 +547,18 @@ class Parser
}
// strip YAML header
preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value);
$count = 0;
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value, -1, $count);
$this->offset += $count;
// remove ---
$value = preg_replace('#^\-\-\-.*?\n#s', '', $value);
// remove leading comments and/or ---
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\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;
}
return $value;
}

View File

@ -38,4 +38,14 @@ brief: >
yaml: |
foo: '#bar'
php: |
array('foo' => '#bar')
array('foo' => '#bar')
---
test: Document starting with a comment and a separator
brief: >
Commenting before document start is allowed
yaml: |
# document comment
---
foo: bar # a comment
php: |
array('foo' => 'bar')

View File

@ -16,7 +16,7 @@ use Symfony\Components\Yaml\Dumper;
Yaml::setSpecVersion('1.1');
$t = new LimeTest(149);
$t = new LimeTest(150);
$parser = new Parser();
$dumper = new Dumper();

View File

@ -16,7 +16,7 @@ use Symfony\Components\Yaml\ParserException;
Yaml::setSpecVersion('1.1');
$t = new LimeTest(149);
$t = new LimeTest(150);
$parser = new Parser();