Thanks to visit codestin.com
Credit goes to github.com

Skip to content

YAML parsing error on perfectly valid JSON #39011

@codebymikey

Description

@codebymikey

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions