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

Skip to content

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

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

Merged
merged 1 commit into from
Jan 1, 2021

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Dec 31, 2020

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

@fabpot
Copy link
Member

fabpot commented Jan 1, 2021

Thank you @xabbuh.

@fabpot fabpot merged commit 04c67e6 into symfony:4.4 Jan 1, 2021
@xabbuh xabbuh deleted the issue-38310 branch January 1, 2021 10:31
@geek-merlin
Copy link

Thanks everyone for caring for and putting time and energy into this! (I'm the person who raised the issue and its predecessor. ;-)

Reviewing the code (unfortunataly i did not catch the unmerged-PR time window), i'm quite sure that this causes regressions:

  • Dumper now always uses the "|-"=strip block chomping indicator, which means "strip all trailing newlines" (it mixes in indentation like "|4-" but that does not change the reasoning)
  • => so the trailing-newlines case should be fixed
  • => but all other cases should break
  • Consistently with this, it looks to me like now we only have "no trailing newline" tests, but no tests with one or more trailing newlines.

What to do? Yaml spec is a convoluted piece of art.
According to the YAML Multiline and tested with this fiddle, we should be able to get away with something like this (plus tests for 0/1/2 trailing newlines):

// Yaml multiline output always needs a trailing newline, 
// so for no trailing newline, tell Yaml to strip it, otherwise to keep them all.
if ("\n" !== $value[-1]) {
  $blockChompingIndicator = '-';
  $value .= "\n";
}
else {
  $blockChompingIndicator = '+';
}

Sorry for not having the bandwidth to forge this into a new PR, but HTH.

@xabbuh
Copy link
Member Author

xabbuh commented Jan 2, 2021

@geek-merlin Thank you for coming back to this. I am going to check the current code with the YAML example that you linked.

@geek-merlin
Copy link

For a radically different multiline alternative see #39682. It does not help with this bugfix, but being in the enlightened state of having groked this corner of Yaml, i quickly needed to do a braindump.

@xabbuh
Copy link
Member Author

xabbuh commented Jan 2, 2021

see #39683 for fixing this regression

fabpot added a commit that referenced this pull request Jan 3, 2021
…ngs (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] keep trailing newlines when dumping multi-line strings

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

Commits
-------

4c513c2 keep trailing newlines when dumping multi-line strings
This was referenced Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants