From 4e0204dfd5d5b2858dac7b0a68a9641474027cad Mon Sep 17 00:00:00 2001 From: Fabian Lange Date: Mon, 22 Feb 2010 15:31:50 +0100 Subject: [PATCH] [Yaml] restored old behaviour of including a trailing newline during parsing. Added test case for empty value --- src/Symfony/Components/Yaml/Parser.php | 9 ++++++--- tests/fixtures/Symfony/Components/Yaml/sfTests.yml | 6 ++++++ tests/unit/Symfony/Components/Yaml/DumperTest.php | 2 +- tests/unit/Symfony/Components/Yaml/ParserTest.php | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Components/Yaml/Parser.php b/src/Symfony/Components/Yaml/Parser.php index aa8323ba9b..2fe6c1d5a3 100644 --- a/src/Symfony/Components/Yaml/Parser.php +++ b/src/Symfony/Components/Yaml/Parser.php @@ -189,7 +189,8 @@ class Parser } 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]); if (is_array($value)) @@ -540,8 +541,10 @@ class Parser { $value = str_replace(array("\r\n", "\r"), "\n", $value); - // remove trailing newlines - $value = rtrim($value, "\n"); + if (!preg_match("#\n$#", $value)) + { + $value .= "\n"; + } // strip YAML header preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value); diff --git a/tests/fixtures/Symfony/Components/Yaml/sfTests.yml b/tests/fixtures/Symfony/Components/Yaml/sfTests.yml index f3dbc84cd8..8eff31c60a 100644 --- a/tests/fixtures/Symfony/Components/Yaml/sfTests.yml +++ b/tests/fixtures/Symfony/Components/Yaml/sfTests.yml @@ -13,6 +13,12 @@ yaml: | php: | array('foo' => array()) --- +test: Empty value +yaml: | + foo: +php: | + array('foo' => null) +--- test: Inline string parsing brief: > Inline string parsing diff --git a/tests/unit/Symfony/Components/Yaml/DumperTest.php b/tests/unit/Symfony/Components/Yaml/DumperTest.php index 7e78a99d13..5b21ce9b63 100644 --- a/tests/unit/Symfony/Components/Yaml/DumperTest.php +++ b/tests/unit/Symfony/Components/Yaml/DumperTest.php @@ -16,7 +16,7 @@ use Symfony\Components\Yaml\Dumper; Yaml::setSpecVersion('1.1'); -$t = new LimeTest(148); +$t = new LimeTest(149); $parser = new Parser(); $dumper = new Dumper(); diff --git a/tests/unit/Symfony/Components/Yaml/ParserTest.php b/tests/unit/Symfony/Components/Yaml/ParserTest.php index a7ab9e4035..e4918af4ae 100644 --- a/tests/unit/Symfony/Components/Yaml/ParserTest.php +++ b/tests/unit/Symfony/Components/Yaml/ParserTest.php @@ -16,7 +16,7 @@ use Symfony\Components\Yaml\ParserException; Yaml::setSpecVersion('1.1'); -$t = new LimeTest(148); +$t = new LimeTest(149); $parser = new Parser();