[Yaml] restored old behaviour of including a trailing newline during parsing. Added test case for empty value

This commit is contained in:
Fabian Lange 2010-02-22 15:31:50 +01:00 committed by Fabien Potencier
parent f87f890b7a
commit 4e0204dfd5
4 changed files with 14 additions and 5 deletions

View File

@ -189,7 +189,8 @@ class Parser
} }
else else
{ {
if (1 == count($this->lines)) // 1-liner followed by newline
if (2 == count($this->lines) && empty($this->lines[1]))
{ {
$value = Inline::load($this->lines[0]); $value = Inline::load($this->lines[0]);
if (is_array($value)) if (is_array($value))
@ -540,8 +541,10 @@ class Parser
{ {
$value = str_replace(array("\r\n", "\r"), "\n", $value); $value = str_replace(array("\r\n", "\r"), "\n", $value);
// remove trailing newlines if (!preg_match("#\n$#", $value))
$value = rtrim($value, "\n"); {
$value .= "\n";
}
// strip YAML header // strip YAML header
preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value); preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value);

View File

@ -13,6 +13,12 @@ yaml: |
php: | php: |
array('foo' => array()) array('foo' => array())
--- ---
test: Empty value
yaml: |
foo:
php: |
array('foo' => null)
---
test: Inline string parsing test: Inline string parsing
brief: > brief: >
Inline string parsing Inline string parsing

View File

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

View File

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