Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Yaml::dump adds erroneous trailing \n (with Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK) #38310

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
geek-merlin opened this issue Sep 26, 2020 · 5 comments

Comments

@geek-merlin
Copy link

geek-merlin commented Sep 26, 2020

Symfony version(s) affected: 3.4.41 (and probably master too)

Description

Yaml::parse(Yaml::dump("a\nb")) === "a\nb\n"

In other words, multiline YML does not roundtrip, it seems to always get a trailing newline.

How to reproduce

# In my Drupal/Drush env:
$ drush ev 'print json_encode(\Symfony\Component\Yaml\Yaml::parse(\Symfony\Component\Yaml\Yaml::dump(["a\nb"],2,4, \Symfony\Component\Yaml\Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK))) . "\n";'
["a\nb\n"]

Possible Solution

Add such test and fix code.

Additional context

@geek-merlin
Copy link
Author

I just updated the IS, it contained a wrong and heavily confusing "How to reproduce". SORRY.

@geek-merlin
Copy link
Author

geek-merlin commented Dec 12, 2020

Convenience: The related PR.

It looks like all the "multiline" tests contain a "\r\n" and iigir, are not dumped as multiline anymore after that PR, leaving us with no multiline test coverage.

@xabbuh
Copy link
Member

xabbuh commented Dec 12, 2020

I forgot to comment here. I was already able to extract a good test case. Unfortunately, the fix wasn't that easy back then when I tried it. But it's on my list of things to do.

@geek-merlin
Copy link
Author

@xabbuh Great it's on your list! As noted in the IS, quite some Drupal folks will ❤️ this.

IIGIR, the key to solve this is the Block Chomping Indicator "|-"/">+".

@xabbuh
Copy link
Member

xabbuh commented Dec 31, 2020

here we go: #39668

@fabpot fabpot closed this as completed Jan 1, 2021
fabpot added a commit that referenced this issue Jan 1, 2021
…locks (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] do not dump extra trailing newlines for multiline blocks

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38310
| License       | MIT
| Doc PR        |

Commits
-------

5fa9592 do not dump extra trailing newlines for multiline blocks
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