Skip to content

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

@hhamon

Description

@hhamon

Hi,

I recently found an issue with the YAML parser. In some circumstances, the YAML parser removes the comments starting with a sharp character in code blocks. This problem only appears when you're configuring an array with embedded code blocks.

The code below works perfectly:

$input = <<<EOF

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

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

    Some footer   # Comment to be removed
EOF;

In the above code sample, all comments are stripped except the one in the code (# hello.html).

But if I put this YAML code inside an YAML array (see below), all comments are stripped, even those inside a code block:

$input = <<<EOF

# 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
EOF;

I think this is a bug we should fix before releasing 2.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions