Description
Symfony version(s) affected: introduced in 4.4.17, thus also 5.1.9 and 5.2.0 if I got that right from the references in #33763
Description
A YAML file, containing white spaces after string values wrapped in quotes causes a parsing exception since Symfony YAML 4.4.17. The file reads fine in version 4.4.16.
Example file: https://github.com/Nexmo/api-specification/blob/51cf4450b3ecf801e7e73da8a4f74a5263894566/definitions/messages-olympus.yml#L28
How to reproduce
<?php
use Symfony\Component\Yaml\Yaml;
// have symfony/yaml:v4.4.17 installed
require __DIR__ . '/vendor/autoload.php';
$data = Yaml::parse(file_get_contents('https://raw.githubusercontent.com/Nexmo/api-specification/51cf4450b3ecf801e7e73da8a4f74a5263894566/definitions/messages-olympus.yml'));
print_r($data);
Output:
Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: Unexpected characters near "/message" " at line 28 (near "$ref: "#/components/schemas/message" "). in /tmp/php-openapi/vendor/symfony/yaml/Parser.php on line 760
...
Possible Solution
Reading the YAML spec I found no clear statement about how these should be handled so I am not sure what the correct solution would be according to the spec.
But I think it makes a lot of sense to restore the previous behavior and ignore trailing white space in such cases as there is no real benefit in being super strict about this. It is also a BC break doing this in a minor release.
Additional context
Problem was introduced in this diff:
symfony/yaml@v4.4.16...v4.4.17 which seems related to #33763