[Yaml] fixed offset when the document use --- or the %YAML element (patch from redotheoffice)
This commit is contained in:
parent
46c4f23496
commit
83023764b6
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -16,7 +16,7 @@ use Symfony\Components\Yaml\ParserException;
|
|||
|
||||
Yaml::setSpecVersion('1.1');
|
||||
|
||||
$t = new LimeTest(149);
|
||||
$t = new LimeTest(150);
|
||||
|
||||
$parser = new Parser();
|
||||
|
||||
|
|
Reference in New Issue