diff --git a/core/lib/Drupal/Component/Serialization/Yaml.php b/core/lib/Drupal/Component/Serialization/Yaml.php index 53f4c41..5e104ba 100644 --- a/core/lib/Drupal/Component/Serialization/Yaml.php +++ b/core/lib/Drupal/Component/Serialization/Yaml.php @@ -38,7 +38,7 @@ public static function decode($raw) { $yaml = new Parser(); // Make sure we have a single trailing newline. A very simple config like // 'foo: bar' with no newline will fail to parse otherwise. - return $yaml->parse(rtrim($raw, "\n") . "\n", TRUE, FALSE); + return $yaml->parse($raw, TRUE, FALSE); } catch (\Exception $e) { throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php index 0677382..94269e6 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php @@ -28,10 +28,19 @@ public function testDecode() { $this->assertSame($expected, Yaml::decode($yaml)); $yaml .= "\n"; $this->assertSame($expected, Yaml::decode($yaml)); + $yaml .= "\n"; + $this->assertSame($expected, Yaml::decode($yaml)); - $yaml = "{}\n\n"; + $yaml = "{}\n"; $expected = array(); $this->assertSame($expected, Yaml::decode($yaml)); + + $yaml = ''; + $this->assertNULL(Yaml::decode($yaml)); + $yaml .= "\n"; + $this->assertNULL(Yaml::decode($yaml)); + $yaml .= "\n"; + $this->assertNULL(Yaml::decode($yaml)); } /**