8000 don't dump a scalar tag value on its own line · symfony/symfony@a549069 · GitHub
[go: up one dir, main page]

Skip to content

Commit a549069

Browse files
committed
don't dump a scalar tag value on its own line
1 parent 6f332ce commit a549069

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Symfony/Component/Yaml/Dumper.php

Lines 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

Lines 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