Skip to content

Commit

Permalink
Merge branch '6.1' into 6.2
Browse files Browse the repository at this point in the history
* 6.1:
  [Mailer] Include all transports' debug messages in RoundRobin transport exception
  [FrameworkBundle] fix: fix help message
  Fix HtmlSanitizer default configuration behavior for allowed schemes
  Use relative timestamps
  [Cache] Fix dealing with ext-redis' multi/exec returning a bool
  [Messenger][Amqp] Added missing rpc_timeout option
  [Serializer] Prevent GetSetMethodNormalizer from creating invalid magic method call
  [HttpFoundation] Fix dumping array cookies
  [WebProfilerBundle] Fix dump header not being displayed
  TraceableHttpClient: increase decorator's priority
  Use static methods inside data providers
  [FrameworkBundle] Allow configuring `framework.exceptions` with a config builder
  bug #48313 [Mime] Fix MessagePart serialization
  [HttpKernel][ErrorHandler] Fix reading the SYMFONY_IDE env var
  [ErrorHandler][DebugClassLoader] Fix some new return types support
  Fix getting the name of closures on PHP 8.1.11+
  [Translator] Fix typo "internal" / "interval"
  fix dumping top-level tagged values
  [Console] Fix clear line with question in section
  • Loading branch information
nicolas-grekas committed Dec 14, 2022
2 parents f2570f2 + ef4e569 commit 6ed8243
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags

if ($inline <= 0 || (!\is_array($input) && !$input instanceof TaggedValue && $dumpObjectAsInlineMap) || empty($input)) {
$output .= $prefix.Inline::dump($input, $flags);
} elseif ($input instanceof TaggedValue) {
$output .= $this->dumpTaggedValue($input, $inline, $indent, $flags, $prefix);
} else {
$dumpAsMap = Inline::isHash($input);

Expand Down Expand Up @@ -135,4 +137,28 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags

return $output;
}

private function dumpTaggedValue(TaggedValue $value, int $inline, int $indent, int $flags, string $prefix): string
{
$output = sprintf('%s!%s', $prefix ? $prefix.' ' : '', $value->getTag());

if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && false !== strpos($value->getValue(), "\n") && false === strpos($value->getValue(), "\r\n")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value->getValue(), 0, 1)) ? (string) $this->indentation : '';
$output .= sprintf(' |%s', $blockIndentationIndicator);

foreach (explode("\n", $value->getValue()) as $row) {
$output .= sprintf("\n%s%s%s", $prefix, str_repeat(' ', $this->indentation), $row);
}

return $output;
}

if ($inline - 1 <= 0 || null === $value->getValue() || \is_scalar($value->getValue())) {
return $output.' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
}

return $output."\n".$this->dump($value->getValue(), $inline - 1, $indent, $flags);
}
}
20 changes: 20 additions & 0 deletions Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,26 @@ public function testDumpingTaggedValueTopLevelAssocInline()
$this->assertSameData($data, $this->parser->parse($yaml, Yaml::PARSE_CUSTOM_TAGS));
}

public function testDumpingTaggedValueTopLevelAssoc()
{
$data = new TaggedValue('user', ['name' => 'jane']);

$expected = <<<'YAML'
!user
name: jane
YAML;
$yaml = $this->dumper->dump($data, 2);
$this->assertSame($expected, $yaml);
}

public function testDumpingTaggedValueTopLevelMultiLine()
{
$data = new TaggedValue('text', "a\nb\n");

$this->assertSame("!text |\n a\n b\n ", $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testDumpingTaggedValueSpecialCharsInTag()
{
// @todo Validate the tag name in the TaggedValue constructor.
Expand Down

0 comments on commit 6ed8243

Please sign in to comment.