From a2079d6e2ee54e8da3081b3796594f61a7457b0b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 22 May 2017 11:14:20 +0200 Subject: [PATCH] [Yaml] fix multiline block handling --- src/Symfony/Component/Yaml/Parser.php | 6 ++- .../Component/Yaml/Tests/ParserTest.php | 50 ++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index dcedd899bc..52cd1867ef 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -368,7 +368,11 @@ class Parser foreach ($this->lines as $line) { try { - $parsedLine = Inline::parse($line, $flags, $this->refs); + if (isset($line[0]) && ('"' === $line[0] || "'" === $line[0])) { + $parsedLine = $line; + } else { + $parsedLine = Inline::parse($line, $flags, $this->refs); + } if (!is_string($parsedLine)) { $parseError = true; diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index f64d7589d8..c8f4a7d40e 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1561,8 +1561,18 @@ EOT; $this->assertEquals("foo bar\nbaz", $this->parser->parse("foo\nbar\n\nbaz")); } - public function testParseMultiLineMappingValue() + /** + * @dataProvider multiLineDataProvider + */ + public function testParseMultiLineMappingValue($yaml, $expected, $parseError) { + $this->assertEquals($expected, $this->parser->parse($yaml)); + } + + public function multiLineDataProvider() + { + $tests = array(); + $yaml = <<<'EOF' foo: - bar: @@ -1579,7 +1589,43 @@ EOF; ), ); - $this->assertEquals($expected, $this->parser->parse($yaml)); + $tests[] = array($yaml, $expected, false); + + $yaml = <<<'EOF' +bar +"foo" +EOF; + $expected = 'bar "foo"'; + + $tests[] = array($yaml, $expected, false); + + $yaml = <<<'EOF' +bar +"foo +EOF; + $expected = 'bar "foo'; + + $tests[] = array($yaml, $expected, false); + + $yaml = <<<'EOF' +bar + +'foo' +EOF; + $expected = "bar\n'foo'"; + + $tests[] = array($yaml, $expected, false); + + $yaml = <<<'EOF' +bar + +foo' +EOF; + $expected = "bar\nfoo'"; + + $tests[] = array($yaml, $expected, false); + + return $tests; } public function testTaggedInlineMapping()