Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7d8577b

Browse filesBrowse files
committed
bug #25864 [Yaml] don't split lines on carriage returns when dumping (xabbuh)
This PR was merged into the 3.3 branch. Discussion ---------- [Yaml] don't split lines on carriage returns when dumping | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25842 | License | MIT | Doc PR | Commits ------- 845eb88 don't split lines on carriage returns when dumping
2 parents bccab35 + 845eb88 commit 7d8577b
Copy full SHA for 7d8577b

File tree

3 files changed

+9
-2
lines changed
Filter options

3 files changed

+9
-2
lines changed

‎src/Symfony/Component/Yaml/Dumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Dumper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
9595
$dumpAsMap = Inline::isHash($input);
9696

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

101101
foreach (preg_split('/\n|\r\n/', $value) as $row) {

‎src/Symfony/Component/Yaml/Tests/DumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ public function testDumpMultiLineStringAsScalarBlock()
443443
$data = array(
444444
'data' => array(
445445
'single_line' => 'foo bar baz',
446-
'multi_line' => "foo\nline with trailing spaces:\n \nbar\r\ninteger like line:\n123456789\nempty line:\n\nbaz",
446+
'multi_line' => "foo\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz",
447+
'multi_line_with_carriage_return' => "foo\nbar\r\nbaz",
447448
'nested_inlined_multi_line_string' => array(
448449
'inlined_multi_line' => "foo\nbar\r\nempty line:\n\nbaz",
449450
),
@@ -453,6 +454,11 @@ public function testDumpMultiLineStringAsScalarBlock()
453454
$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));
454455
}
455456

457+
public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
458+
{
459+
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(array("a\r\nb\nc"), 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
460+
}
461+
456462
/**
457463
* @expectedException \InvalidArgumentException
458464
* @expectedExceptionMessage The indentation must be greater than zero

‎src/Symfony/Component/Yaml/Tests/Fixtures/multiple_lines_as_literal_block.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/Fixtures/multiple_lines_as_literal_block.yml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ data:
1010
empty line:
1111
1212
baz
13+
multi_line_with_carriage_return: "foo\nbar\r\nbaz"
1314
nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.