8000 YAML DUMP_MULTI_LINE_LITERAL_BLOCK question, possible bug · Issue #20706 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

YAML DUMP_MULTI_LINE_LITERAL_BLOCK question, possible bug #20706

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
lauradean opened this issue Nov 30, 2016 · 3 comments
Closed

YAML DUMP_MULTI_LINE_LITERAL_BLOCK question, possible bug #20706

lauradean opened this issue Nov 30, 2016 · 3 comments

Comments

@lauradean
Copy link
lauradean commented Nov 30, 2016

In outputting an array to YAML, my multi-line strings were not being output as literals, but I found that if I changed the line in Dumper.php from

if ($inline > 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK
    & $flags && is_string($value) && false !== strpos($value, "\n")) {

to

if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK
    & $flags && is_string($value) && false !== strpos($value, "\n")) {

then it works perfectly.

Is there a reason for checking for $inline > 1?

@xabbuh
Copy link
Member
xabbuh commented Dec 1, 2016

@lauradean Thank you for reporting this issue. Can you please also show us the code you used to dump as well as the array to be dumped?

@lauradean
Copy link
Author

Here is the line of code to create the Yaml:

$yaml = Yaml::dump($result, 3, 4, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);

The real array is too long and contains sensitive information and html that will not display properly, but here is something similar, as would be output by print_r:

Array
(
    [test] => Array
        (
            [0] => Array
                (
                    [key_1] => This is a single-line value.
                    [key_2] => This is a multi-line value.
It has two lines.
                )
        )
)

Here is the desired YAML output, which worked after I put in the above code change:

test:
    -
        key_1: 'This is a single-line value.'
        key_2: |
            This is a multi-line value.
            It has two lines.

(I did not test this specific array.)

@xabbuh
Copy link
Member
xabbuh commented Dec 3, 2016

I think you are right. See #20732 which will resolve your issue.

@xabbuh xabbuh removed the Unconfirmed label Dec 3, 2016
fabpot added a commit that referenced this issue Dec 3, 2016
This PR was merged into the 3.1 branch.

Discussion
----------

fix the inline level for dumped multi-line strings

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

Commits
-------

5269796 fix the inline level for dumped multi-line strings
@fabpot fabpot closed this as completed Dec 3, 2016
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

5 participants
0