bug #20732 fix the inline level for dumped multi-line strings (xabbuh)

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
This commit is contained in:
Fabien Potencier 2016-12-03 12:35:23 +01:00
commit b699e4b77b
3 changed files with 3 additions and 4 deletions

View File

@ -88,7 +88,7 @@ class Dumper
$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) {

View File

@ -342,7 +342,7 @@ EOF;
),
);
$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));
}
/**

View File

@ -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" }