Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 272fe5a

Browse files
committed
YAML mutli-line literal: emit block indentiation indicator
When dumping YAML: When the first line of a multi-line string literal starts with a space, emit a block indentation indicator. As per spec at: http://www.yaml.org/spec/1.2/spec.html#id2793979 Issue #26065
1 parent 752f8d2 commit 272fe5a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
9898

9999
foreach ($input as $key => $value) {
100100
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
101-
$output .= sprintf("%s%s%s |\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '');
101+
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
102+
// http://www.yaml.org/spec/1.2/spec.html#id2793979
103+
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
104+
$output .= sprintf("%s%s%s |%s\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator);
102105

103106
foreach (preg_split('/\n|\r\n/', $value) as $row) {
104107
$output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);

0 commit comments

Comments
 (0)