-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected: symfony/yaml:3.4.35, symfony/yaml:5.1.8
The issue affects the latest version at time of writing.
Description
YAML fails to parse perfectly valid JSON, even though YAML is a superset of JSON:
[
["entry1", {}],
["entry2", {"entry3": "entryvalue"}]
]
The YAML/JSON passes when ran on http://www.yamllint.com and https://yaml-online-parser.appspot.com.
How to reproduce
// composer.json
{
"name": "demo/yaml-bug",
"require": {
"symfony/yaml": "^5.1"
}
}
<?php
require_once 'vendor/autoload.php';
use Symfony\Component\Yaml\Parser;
$yaml = new Parser();
$yaml_content = <<<YAML
[
["entry1", {}],
["entry2", {"entry3": "entryvalue"}]
]
YAML;
$yaml->parse($yaml_content);
throws the following:
PHP Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException:
Malformed inline YAML string: "[["entry1", {}]," at line 2 (near " ["entry1", {}],").
Possible Solution
To avoid issues like this continuously happening, I believe the library should be capable of parsing every single YAML in the https://github.com/yaml/yaml-test-suite repo.
Or at the bare minimum other valid JSON.
e.g. the first test file I picked up from that repository isn't currently parseable either.