浏览代码

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

Fabian Lange 15 年之前
父节点
当前提交
4e0204dfd5

+ 6 - 3
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);

+ 6 - 0
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

+ 1 - 1
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();

+ 1 - 1
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();