Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
W0rma opened this issue Dec 21, 2016 · 4 comments
Closed

Comments

@W0rma
Copy link
Contributor

W0rma commented Dec 21, 2016

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();
}
@W0rma W0rma changed the title [YAML] [YAML] Yaml::parse() does not handle empty lines in mulitline sequence elements Dec 21, 2016
@stof
Copy link
Member

stof commented Dec 21, 2016

there is a difference between your 2 cases: in the second case, the line is not empty, but contains the indentation whitespaces like the bla lines. This may be why it works.

@W0rma
Copy link
Contributor Author

W0rma commented Dec 21, 2016

I've updated my post. Case 2 works even if the line is empty

@xabbuh
Copy link
Member

xabbuh commented Dec 28, 2016

@W0rma Can you confirm that #21084 fixes your issue?

fabpot added a commit that referenced this issue Jan 3, 2017
…bbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Yaml] handle empty lines inside unindented collection

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21005
| License       | MIT
| Doc PR        |

Commits
-------

bbfe6f7 handle empty lines inside unindented collection
@fabpot fabpot closed this as completed Jan 3, 2017
@W0rma
Copy link
Contributor Author

W0rma commented Jan 9, 2017

@xabbuh Yes, issue is fixed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants