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 f7130e3

Browse filesBrowse files
committed
bug #33518 [Yaml] don't dump a scalar tag value on its own line (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] don't dump a scalar tag value on its own line | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This commit fine tunes the bugfix made in #33377 with the feedback provided in #33464 (comment). Commits ------- a549069 don't dump a scalar tag value on its own line
2 parents f436cc8 + a549069 commit f7130e3
Copy full SHA for f7130e3

File tree

2 files changed

+16
-9
lines changed
Filter options

2 files changed

+16
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Dumper.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,11 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
115115
if ($value instanceof TaggedValue) {
116116
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
117117

118-
if ($inline - 1 <= 0) {
118+
if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) {
119119
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
120120
} else {
121121
$output .= "\n";
122122
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
123-
124-
if (is_scalar($value->getValue())) {
125-
$output .= "\n";
126-
}
127123
}
128124

129125
continue;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,21 @@ public function testDumpingNotInlinedScalarTaggedValue()
532532
'user2' => new TaggedValue('user', 'john'),
533533
];
534534
$expected = <<<YAML
535-
user1: !user
536-
jane
537-
user2: !user
538-
john
535+
user1: !user jane
536+
user2: !user john
537+
538+
YAML;
539+
540+
$this->assertSame($expected, $this->dumper->dump($data, 2));
541+
}
542+
543+
public function testDumpingNotInlinedNullTaggedValue()
544+
{
545+
$data = [
546+
'foo' => new TaggedValue('bar', null),
547+
];
548+
$expected = <<<YAML
549+
foo: !bar null
539550
540551
YAML;
541552

0 commit comments

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