Преглед изворни кода

[Yaml] fixed parsing of folded scalars when a # sign starts a line

Fabien Potencier пре 15 година
родитељ
комит
7d19d8e375

+ 2 - 5
src/Symfony/Components/Yaml/Parser.php

@@ -300,12 +300,9 @@ class Parser
 
     while ($this->moveToNextLine())
     {
-      if ($this->isCurrentLineEmpty())
+      if ($this->isCurrentLineBlank())
       {
-        if ($this->isCurrentLineBlank())
-        {
-          $data[] = substr($this->currentLine, $newIndent);
-        }
+        $data[] = substr($this->currentLine, $newIndent);
 
         continue;
       }

+ 28 - 0
tests/fixtures/Symfony/Components/Yaml/sfTests.yml

@@ -143,3 +143,31 @@ yaml: |
     0123
 php: |
   array('foo' => "0123\n")
+---
+test: Comments in folded scalars
+brief: Comments in folded scalars should be kept as is
+yaml: |
+  # comment
+  foo: |
+    # comment
+    bar
+  bar:
+    # comment
+    foo: bar # comment
+    bar: |
+      # comment
+      foo
+    foobar:
+      foo: |
+        # comment
+        bar
+  # comment
+php: |
+  array(
+    'foo' => "# comment\nbar\n",
+    'bar' => array(
+      'foo' => 'bar',
+      'bar' => "# comment\nfoo\n",
+      'foobar' => array('foo' => "# comment\nbar\n")
+    )
+  )

+ 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(150);
+$t = new LimeTest(151);
 
 $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(150);
+$t = new LimeTest(151);
 
 $parser = new Parser();