diff --git a/core/lib/Drupal/Component/Serialization/Yaml.php b/core/lib/Drupal/Component/Serialization/Yaml.php index 7d0f0c5..5792375 100644 --- a/core/lib/Drupal/Component/Serialization/Yaml.php +++ b/core/lib/Drupal/Component/Serialization/Yaml.php @@ -32,7 +32,9 @@ public static function encode($data) { */ public static function decode($raw) { try { - return Symfony::parse($raw, TRUE); + // If you have YAML data without a line break in it, like foo: bar then + // that will be misinterpreted as a filename. + return Symfony::parse(rtrim($raw) . "\n", TRUE); } 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 new file mode 100644 index 0000000..0677382 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php @@ -0,0 +1,54 @@ + 'bar', + ); + $this->assertSame($expected, Yaml::decode($yaml)); + $yaml .= "\n"; + $this->assertSame($expected, Yaml::decode($yaml)); + + $yaml = "{}\n\n"; + $expected = array(); + $this->assertSame($expected, Yaml::decode($yaml)); + } + + /** + * @covers ::encode + */ + public function testEncode() { + $decoded = array( + 'foo' => 'bar', + ); + $this->assertSame('foo: bar' . "\n", Yaml::encode($decoded)); + } + + /** + * @covers ::getFileExtension + */ + public function testGetFileExtension() { + $this->assertEquals('yml', Yaml::getFileExtension()); + } + +}