Skip to content
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

[YAML] Comments after blank lines are read as value #32667

Closed
YujiSoftware opened this issue Jul 23, 2019 · 0 comments
Closed

[YAML] Comments after blank lines are read as value #32667

YujiSoftware opened this issue Jul 23, 2019 · 0 comments

Comments

@YujiSoftware
Copy link

Symfony version(s) affected: 3.4.27
I reproduce symfony/yaml@e464640

Description
Comments after blank lines are read as value in yaml.

How to reproduce

$yaml = <<<YAML
parameters:
    abc

# Comment 
YAML;

var_dump(Symfony\Component\Yaml\Yaml::parse($yaml));

Actual result:

array(1) {
  ["parameters"]=>
  string(13) "abc
# Comment"
}

Expected result:

array(1) {
  ["parameters"]=>
  string(3) "abc"
}

Possible Solution
Ignore comment line.

Additional context
When I tested some Online YAML parser, I got the expected results.
https://yaml-online-parser.appspot.com/?yaml=parameters%3A%0A++++abc%0A%0A%23+Comment%0A&type=json
http://nodeca.github.io/js-yaml/#yaml=cGFyYW1ldGVyczoKICAgIGFiYwoKIyBDb21tZW50IAo=

nicolas-grekas added a commit that referenced this issue Jul 30, 2019
This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml] fix comment in multi line value

| Q             | A
| ------------- | ---
| Branch?       |  4.3 and lower <!-- see below -->
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #32667    <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->
Comments after blank lines are read as value in yaml.

```
`$yaml = <<<YAML
parameters:
    abc

# Comment
YAML;

var_dump(Symfony\Component\Yaml\Yaml::parse($yaml));`
```

**Result before fix:**

```
array(1) {
  ["parameters"]=>
  string(13) "abc
# Comment"
}
```
**Result after fix:**

```
array(1) {
  ["parameters"]=>
  string(3) "abc"
}
```

Commits
-------

dd945e3 fix(yml): fix comment in milti line value
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

4 participants