Skip to content

Commit

Permalink
bug #20732 fix the inline level for dumped multi-line strings (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.1 branch.

Discussion
----------

fix the inline level for dumped multi-line strings

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20706
| License       | MIT
| Doc PR        |

Commits
-------

5269796 fix the inline level for dumped multi-line strings
  • Loading branch information
fabpot committed Dec 3, 2016
2 parents b9ed4bf + 5269796 commit b699e4b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
$isAHash = Inline::isHash($input);

foreach ($input as $key => $value) {
if ($inline > 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
$output .= sprintf("%s%s%s |\n", $prefix, $isAHash ? Inline::dump($key, $flags).':' : '-', '');

foreach (preg_split('/\n|\r\n/', $value) as $row) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function testDumpMultiLineStringAsScalarBlock()
),
);

$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 3, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ data:
empty line:
baz
nested_inlined_multi_line_string:
inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz"
nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" }

0 comments on commit b699e4b

Please sign in to comment.