Skip to content

Commit

Permalink
bug #33518 [Yaml] don't dump a scalar tag value on its own line (xabbuh)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Sep 10, 2019
2 parents f436cc8 + a549069 commit f7130e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/Symfony/Component/Yaml/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,11 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
if ($value instanceof TaggedValue) {
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());

if ($inline - 1 <= 0) {
if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) {
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
} else {
$output .= "\n";
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);

if (is_scalar($value->getValue())) {
$output .= "\n";
}
}

continue;
Expand Down
19 changes: 15 additions & 4 deletions src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,21 @@ public function testDumpingNotInlinedScalarTaggedValue()
'user2' => new TaggedValue('user', 'john'),
];
$expected = <<<YAML
user1: !user
jane
user2: !user
john
user1: !user jane
user2: !user john
YAML;

$this->assertSame($expected, $this->dumper->dump($data, 2));
}

public function testDumpingNotInlinedNullTaggedValue()
{
$data = [
'foo' => new TaggedValue('bar', null),
];
$expected = <<<YAML
foo: !bar null
YAML;

Expand Down

0 comments on commit f7130e3

Please sign in to comment.