Skip to content

[YAML] Regression in parsing inline objects since version 4.4 #34805

@cebe

Description

@cebe

Symfony version(s) affected: 4.4.x (it works in 3.x as well as 4.x up to 4.3, 4.4 or greater is failing)

Description

Parsing inline Objects in YAML is broken since 4.4, see example script below.

How to reproduce

<?php
require __DIR__ . '/vendor/autoload.php';

$yaml = \Symfony\Component\Yaml\Yaml::parse(<<<YAML
data:
  example:
    {
      "total": 2,
      "apis": [
        {
          "apiKey": "oa_citations",
          "apiVersionNumber": "v1",
        },
        {
          "apiKey": "cancer_moonshot",
          "apiVersionNumber": "v1",
        }
      ]
    }
YAML
);

print_r($yaml);

On yaml versions <4.4, it shows the correct parsing:

Array
(
    [data] => Array
        (
            [example] => Array
                (
                    [total] => 2
                    [apis] => Array
                        (
                            [0] => Array
                                (
                                    [apiKey] => oa_citations
                                    [apiVersionNumber] => v1
                                )
                            [1] => Array
                                (
                                    [apiKey] => cancer_moonshot
                                    [apiVersionNumber] => v1
                                )
                        )
                )
        )
)

since 4.4 I get the following error:

Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: Malformed inline YAML string: {
  "total": 2,
  "apis": [
    {
      "apiKey": "oa_citations",
      "apiVersionNumber": "v1",
    },
    {
      "apiKey": "cancer_moonshot",
      "apiVersionNumber": "v1",
    }
  ]
} at line 15 (near "}"). in /home/cebe/dev/layer5/layer5-ng/vendor-dev/cebe/php-openapi/vendor/symfony/yaml/Inline.php on line 300

Symfony\Component\Yaml\Exception\ParseException: Malformed inline YAML string: {
  "total": 2,
  "apis": [
    {
      "apiKey": "oa_citations",
      "apiVersionNumber": "v1",
    },
    {
      "apiKey": "cancer_moonshot",
      "apiVersionNumber": "v1",
    }
  ]
} at line 15 (near "}"). in /home/cebe/dev/layer5/layer5-ng/vendor-dev/cebe/php-openapi/vendor/symfony/yaml/Inline.php on line 300

Additional info

could be related to symfony/yaml@110e3e9 (#33658)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions