Skip to content
/ yaml Public
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/yaml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.1.11
Choose a base ref
...
head repository: symfony/yaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.2.0
Choose a head ref
  • 16 commits
  • 12 files changed
  • 7 contributors

Commits on Jun 2, 2024

  1. [Yaml] Throw on duplicate key even when value is NULL

    olsavmic authored and fabpot committed Jun 2, 2024
    Copy the full SHA
    412589d View commit details

Commits on Jun 18, 2024

  1. Add more precise types for the Yaml flags

    stof committed Jun 18, 2024
    Copy the full SHA
    14a66d3 View commit details

Commits on Jun 20, 2024

  1. Prefix all sprintf() calls

    derrabus committed Jun 20, 2024
    Copy the full SHA
    691075a View commit details

Commits on Jun 25, 2024

  1. [Yaml] Fix typo in changelog

    alexandre-daubois committed Jun 25, 2024
    Copy the full SHA
    cc0c313 View commit details

Commits on Jun 26, 2024

  1. Copy the full SHA
    ec6a914 View commit details
  2. feature #57518 Unify how --format is handled by commands (fabpot)

    This PR was merged into the 7.2 branch.
    
    Discussion
    ----------
    
    Unify how --format is handled by commands
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 7.2
    | Bug fix?      | no
    | New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
    | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
    | Issues        | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
    | License       | MIT
    
    We have many commands that have a `--format` option. This PR tries to unify the way we handle them:
    
    * Deprecate the `text` format (used only twice) in favor of the more common `txt` one;
    * Add auto-completion for `--format` in all commands;
    * Add help about the `--format` option in all commands that supports it (in a unified way)
    
    **Side note**: To avoid confusion, I think we should rename the `--format` option for the `uuid:generate` and `ulid:generate` commands as it does something different from the commonly used `--format` option.
    
    Commits
    -------
    
    848f855cdf Unify how --format is handle by commands
    fabpot committed Jun 26, 2024
    Copy the full SHA
    4c5e237 View commit details

Commits on Jun 29, 2024

  1. Deprecate duplicate mapping keys containing null

    xabbuh committed Jun 29, 2024
    Copy the full SHA
    9175fd2 View commit details

Commits on Jul 6, 2024

  1. Update .gitattributes

    fabpot committed Jul 6, 2024
    Copy the full SHA
    aaf847b View commit details

Commits on Jul 22, 2024

  1. [PhpUnitBridge] Add ExpectUserDeprecationMessageTrait

    derrabus committed Jul 22, 2024
    Copy the full SHA
    9a80908 View commit details

Commits on Aug 5, 2024

  1. Fix multiple CS errors

    alexandre-daubois committed Aug 5, 2024
    Copy the full SHA
    564ae85 View commit details

Commits on Aug 8, 2024

  1. Remove useless code

    alexandre-daubois committed Aug 8, 2024
    Copy the full SHA
    9900d69 View commit details

Commits on Aug 12, 2024

  1. Merge branch '7.1' into 7.2

    * 7.1: (31 commits)
      [Serializer] Remove useless calls to `func_get_arg()`
      fix tests using Twig 3.12
      skip tests requiring the intl extension if it's not installed
      🐛 throw ParseException on invalid date
      [FrameworkBundle] Re-remove redundant name attribute from `default_context`
      fix permitted data type of the default choice
      [ExpressionLanguage] Improve test coverage
      Fix invalid phpdoc in ContainerBuilder
      [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon
      [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent
      Fix importing PHP config in prepend extension method
      [Messenger] Prevent waiting time to overflow when using long delays
      [Security] consistent singular/plural translation in Dutch
      reset the validation context after validating nested constraints
      do not duplicate directory separators
      fix handling empty data in ValueToDuplicatesTransformer
      fix compatibility with redis extension 6.0.3+
      synchronize unsupported scheme tests
      [String] Fixed Quorum plural, that was inflected to be only "Quora" and never "Quorums"
      Fix symfony/kaz-info-teh-notifier package
      ...
    xabbuh committed Aug 12, 2024
    Copy the full SHA
    4bc6a9f View commit details

Commits on Sep 17, 2024

  1. Merge branch '7.1' into 7.2

    * 7.1:
      [Process] minor fix
      [Process] Fix finding executables independently of open_basedir
      [HttpKernel] Skip logging uncaught exceptions in ErrorHandler, assume $kernel->terminateWithException() will do it
      [Serializer] Fix for method named `get()`
      [Notifier][TurboSMS] Process partial accepted response from transport
      parse empty sequence elements as null
      [HttpClient] Fix setting CURLMOPT_MAXCONNECTS
      throw a meaningful exception when parsing dotenv files with BOM
      [FrameworkBundle] Fix schema & finish incomplete tests for lock & semaphore config
      [Cache] Fix RedisSentinel params types
      [FrameworkBundle] Fix service reset between tests
      [Uid][Serializer][Validator] Mention RFC 9562
      make sure temp files can be cleaned up on Windows
    nicolas-grekas committed Sep 17, 2024
    Copy the full SHA
    96baa90 View commit details

Commits on Sep 23, 2024

  1. [Yaml] Use CPP in Dumper

    alexandre-daubois committed Sep 23, 2024
    Copy the full SHA
    8e82cc9 View commit details

Commits on Sep 25, 2024

  1. Merge branch '7.1' into 7.2

    * 7.1:
      Add PR template and auto-close PR on subtree split repositories
    nicolas-grekas committed Sep 25, 2024
    Copy the full SHA
    888f0ea View commit details

Commits on Oct 23, 2024

  1. Remove always true/false occurrences

    alexandre-daubois committed Oct 23, 2024
    Copy the full SHA
    099581e View commit details
Showing with 136 additions and 98 deletions.
  1. +5 −0 CHANGELOG.md
  2. +12 −8 Command/LintCommand.php
  3. +15 −19 Dumper.php
  4. +2 −2 Escaper.php
  5. +3 −3 Exception/ParseException.php
  6. +31 −31 Inline.php
  7. +30 −18 Parser.php
  8. +6 −6 Tests/InlineTest.php
  9. +22 −2 Tests/ParserTest.php
  10. +1 −1 Unescaper.php
  11. +8 −8 Yaml.php
  12. +1 −0 composer.json
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.2
---

* Deprecate parsing duplicate mapping keys whose value is `null`

7.1
---

20 changes: 12 additions & 8 deletions Command/LintCommand.php
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ protected function configure(): void
{
$this
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
->addOption('format', null, InputOption::VALUE_REQUIRED, \sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
->addOption('exclude', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Path(s) to exclude')
->addOption('parse-tags', null, InputOption::VALUE_NEGATABLE, 'Parse custom tags', null)
->setHelp(<<<EOF
@@ -72,6 +72,9 @@ protected function configure(): void
Or of a whole directory:
<info>php %command.full_name% dirname</info>
The <info>--format</info> option specifies the format of the command output:
<info>php %command.full_name% dirname --format=json</info>
You can also exclude one or more specific files:
@@ -111,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$filesInfo = [];
foreach ($filenames as $filename) {
if (!$this->isReadable($filename)) {
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
throw new RuntimeException(\sprintf('File or directory "%s" is not readable.', $filename));
}

foreach ($this->getFiles($filename) as $file) {
@@ -151,7 +154,7 @@ private function display(SymfonyStyle $io, array $files): int
'txt' => $this->displayTxt($io, $files),
'json' => $this->displayJson($io, $files),
'github' => $this->displayTxt($io, $files, true),
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
default => throw new InvalidArgumentException(\sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
};
}

@@ -167,11 +170,11 @@ private function displayTxt(SymfonyStyle $io, array $filesInfo, bool $errorAsGit

foreach ($filesInfo as $info) {
if ($info['valid'] && $this->displayCorrectFiles) {
$io->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
$io->comment('<info>OK</info>'.($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
} elseif (!$info['valid']) {
++$erroredFiles;
$io->text('<error> ERROR </error>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
$io->text(sprintf('<error> >> %s</error>', $info['message']));
$io->text('<error> ERROR </error>'.($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
$io->text(\sprintf('<error> >> %s</error>', $info['message']));

if (str_contains($info['message'], 'PARSE_CUSTOM_TAGS')) {
$suggestTagOption = true;
@@ -184,9 +187,9 @@ private function displayTxt(SymfonyStyle $io, array $filesInfo, bool $errorAsGit
}

if (0 === $erroredFiles) {
$io->success(sprintf('All %d YAML files contain valid syntax.', $countFiles));
$io->success(\sprintf('All %d YAML files contain valid syntax.', $countFiles));
} else {
$io->warning(sprintf('%d YAML files have valid syntax and %d contain errors.%s', $countFiles - $erroredFiles, $erroredFiles, $suggestTagOption ? ' Use the --parse-tags option if you want parse custom tags.' : ''));
$io->warning(\sprintf('%d YAML files have valid syntax and %d contain errors.%s', $countFiles - $erroredFiles, $erroredFiles, $suggestTagOption ? ' Use the --parse-tags option if you want parse custom tags.' : ''));
}

return min($erroredFiles, 1);
@@ -266,6 +269,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
}
}

/** @return string[] */
private function getAvailableFormatOptions(): array
{
return ['txt', 'json', 'github'];
34 changes: 15 additions & 19 deletions Dumper.php
Original file line number Diff line number Diff line change
@@ -23,26 +23,22 @@
class Dumper
{
/**
* The amount of spaces to use for indentation of nested nodes.
* @param int $indentation The amount of spaces to use for indentation of nested nodes
*/
private int $indentation;

public function __construct(int $indentation = 4)
public function __construct(private int $indentation = 4)
{
if ($indentation < 1) {
throw new \InvalidArgumentException('The indentation must be greater than zero.');
}

$this->indentation = $indentation;
}

/**
* Dumps a PHP value to YAML.
*
* @param mixed $input The PHP value
* @param int $inline The level where you switch to inline YAML
* @param int $indent The level of indentation (used internally)
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
* @param mixed $input The PHP value
* @param int $inline The level where you switch to inline YAML
* @param int $indent The level of indentation (used internally)
* @param int-mask-of<Yaml::DUMP_*> $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
*/
public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags = 0): string
{
@@ -81,28 +77,28 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags
$blockChompingIndicator = '-';
}

$output .= sprintf('%s%s%s |%s%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator, $blockChompingIndicator);
$output .= \sprintf('%s%s%s |%s%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator, $blockChompingIndicator);

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

continue;
}

if ($value instanceof TaggedValue) {
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
$output .= \sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());

if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value->getValue());
$output .= sprintf(' |%s', $blockIndentationIndicator);
$output .= \sprintf(' |%s', $blockIndentationIndicator);

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

continue;
@@ -126,7 +122,7 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags

$willBeInlined = $inline - 1 <= 0 || !\is_array($value) && $dumpObjectAsInlineMap || !$value;

$output .= sprintf('%s%s%s%s',
$output .= \sprintf('%s%s%s%s',
$prefix,
$dumpAsMap ? Inline::dump($key, $flags).':' : '-',
$willBeInlined ? ' ' : "\n",
@@ -140,14 +136,14 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags

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

if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value->getValue());
$output .= sprintf(' |%s', $blockIndentationIndicator);
$output .= \sprintf(' |%s', $blockIndentationIndicator);

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

return $output;
4 changes: 2 additions & 2 deletions Escaper.php
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public static function requiresDoubleQuoting(string $value): bool
*/
public static function escapeWithDoubleQuotes(string $value): string
{
return sprintf('"%s"', str_replace(self::ESCAPEES, self::ESCAPED, $value));
return \sprintf('"%s"', str_replace(self::ESCAPEES, self::ESCAPED, $value));
}

/**
@@ -90,6 +90,6 @@ public static function requiresSingleQuoting(string $value): bool
*/
public static function escapeWithSingleQuotes(string $value): string
{
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
return \sprintf("'%s'", str_replace('\'', '\'\'', $value));
}
}
6 changes: 3 additions & 3 deletions Exception/ParseException.php
Original file line number Diff line number Diff line change
@@ -103,15 +103,15 @@ private function updateRepr(): void
}

if (null !== $this->parsedFile) {
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
$this->message .= \sprintf(' in %s', json_encode($this->parsedFile, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
}

if ($this->parsedLine >= 0) {
$this->message .= sprintf(' at line %d', $this->parsedLine);
$this->message .= \sprintf(' at line %d', $this->parsedLine);
}

if ($this->snippet) {
$this->message .= sprintf(' (near "%s")', $this->snippet);
$this->message .= \sprintf(' (near "%s")', $this->snippet);
}

if ($dot) {
Loading