Skip to content

[YAML] Multiline string as scalar block for tagged values #34450

Closed
@natepage

Description

@natepage

Symfony version(s) affected: 3.4 to latest

Description
The Yaml component is able to parse scalar bock for tagged values:

foo: !bar |
    foo
    another line

If parse the above YAML string you will get the expected TaggedValue containing the string with line breaks, amazing!

However if you try to dump a PHP value to this YAML string you are not getting the intended output but the following:

foo: !bar "foo\nanother line"

And that's because the parsing tag Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK isn't used for tagged value.

How to reproduce
Try to dump a PHP value containing a TaggedValue with a string with line breaks as a value while the tag Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK is passed.

use Symfony\Component\Yaml\Tag\TaggedValue;
use Symfony\Component\Yaml\Yaml;

$php = ['foo' => new TaggedValue('bar', "foo\nanother line")];
$yaml = Yaml::dump($php, 1, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);

Possible Solution
If this is identified as a legit issue, I've created a PR to fix it. #34449

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