Skip to content

[YAML] Yaml::parse() does not handle empty lines in mulitline sequence elements #21005

@W0rma

Description

@W0rma
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes
Symfony version 2.8.15

The Yaml::parse() seems to have problems if an element of a sequence contains a multiline string containg an empty line:

$raw = <<<YAML
---
foo:
  bar:
  - field1: value
    field2: |
      bla

      bla
      bla
YAML;

try {
    \Symfony\Component\Yaml\Yaml::parse($raw);
} catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
    // Exception is thrown
    $e->getMessage();
}

This example results in a ParseException with the message Unable to parse at line 8 (near " bla")..

If empty lines are used outside the sequence, Yaml::parse() does not throw the Exception. F.e. this example works fine:

    $raw = <<<YAML
---
foo:
  bar:
  - field1: value
    field2: |
      bla
      bla
      bla
  bar2: |
      bla

      bla
      bla
YAML;

\Symfony\Component\Yaml\Yaml::parse($raw);

try {
    \Symfony\Component\Yaml\Yaml::parse($raw);
} catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
    // Exception is thrown
    $e->getMessage();
}

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