8000 [YAML] Comments are stripped in code blocks when configuring an array · Issue #8779 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div id="repo-content-pjax-container" class="repository-content " >

[YAML] Comments are stripped in code blocks when configuring an array #8779

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
hhamon opened this issue Aug 17, 2013 · 1 comment
Closed

Comments

@hhamon
Copy link
Contributor
hhamon commented Aug 17, 2013

Hi,

The previous issue (#8145) I opened 2 months ago was fixed by @jfsimon.

Unfortunately the fix only works for a special case but not all.

The current YAML parser in version 2.3.3 works for the following case (as fixed by @jfsimon):

# Comment to be removed
-
    # Comment to be removed
    content: |
        Some header

            # index.html
            <body>
                <h1>My title</h1>
            </body>

        Some footer   # Comment to be removed
    title: An HTML tutorial

Comments to be stripped are correctly stripped and those to be kept are correctly kept as expected. But if you inverse the associative keys in the yaml string (title first and then content instead of content first and title second) all comments are stripped!

This behavior looks weird but I was able to prove it with a failing unit test as shown below:

<?php
// ...
class ParserTest extends \PHPUnit_Framework_TestCase
{
    /...
    // This test passes
    public function testArrayWithEmbeddedCommentedBlock()
    {
        $yaml = '# comment 1
header

    # comment 2
    <body>
        <h1>title</h1>
    </body>

footer # comment3
';

        $this->assertEquals(array(array(
            'content' => $yaml,
            'title' => 'some title',
        )), Yaml::parse(<<<EOF
-
    content: |
        # comment 1
        header

            # comment 2
            <body>
                <h1>title</h1>
            </body>

        footer # comment3
    title: some title
EOF
        ));
    }

    // This same test fails
    public function testArrayWithEmbeddedCommentedBlock2()
    {
        $yaml = '# comment 1
header

    # comment 2
    <body>
        <h1>title</h1>
    </body>

footer # comment3
';

        $this->assertEquals(array(array(
            'title' => 'some title',
            'content' => $yaml,
        )), Yaml::parse(<<<EOF
-
    title: some title
    content: |
        # comment 1
        header

            # comment 2
            <body>
                <h1>title</h1>
            </body>

        footer # comment3
EOF
        ));
    }
}
@hhamon
Copy link
Contributor Author
hhamon commented Aug 17, 2013

This issue is related to #8145

fabpot added a commit that referenced this issue Aug 24, 2013
This PR was merged into the 2.2 branch.

Discussion
----------

[Yaml] fixed embedded folded string parsing

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8779

Commits
-------

566d79c [Yaml] fixed embedded folded string parsing
@fabpot fabpot closed this as completed Aug 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0