Skip to content

Commit

Permalink
bug #22853 [Yaml] fix multiline block handling (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.3 branch.

Discussion
----------

[Yaml] fix multiline block handling

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21114, #22105 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

a2079d6 [Yaml] fix multiline block handling
  • Loading branch information
fabpot committed May 24, 2017
2 parents aef39bc + a2079d6 commit 047a06e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -368,7 +368,11 @@ private function doParse($value, $flags)

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;
Expand Down
50 changes: 48 additions & 2 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -1561,8 +1561,18 @@ public function testParseMultiLineString()
$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:
Expand All @@ -1579,7 +1589,43 @@ public function testParseMultiLineMappingValue()
),
);

$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()
Expand Down

0 comments on commit 047a06e

Please sign in to comment.