Skip to content

fix(ast): preserve keep-chomped trailing blank lines in block scalars - #969

Open
gyanu2507 wants to merge 1 commit into
goccy:masterfrom
gyanu2507:fix/block-scalar-keep-trailing-blanks-826
Open

gyanu2507 wants to merge 1 commit into
goccy:masterfrom
gyanu2507:fix/block-scalar-keep-trailing-blanks-826

Conversation

@gyanu2507

Copy link
Copy Markdown

Fixes #826.

LiteralNode.String() always ran TrimRight(..., "\n") on the scalar Origin. For | / |- that is fine. For |+ keep chomping it dropped the trailing blank lines, so parser.Parse then File.String() lost them and a decode of the rewritten YAML no longer matched.

Changes:

  • Keep trailing newlines in Origin when the header is |+ or >+.
  • When joining block mapping entries, do not insert another separator if the previous value already ends with a newline (otherwise keep blanks get inflated by one).
  • In checkLineBreak, count those keep-chomped trailing blanks on the previous string token so the next key does not emit them a second time.

Test plan:

  • New TestKeepBlockScalarTrailingBlanks round-trips the issue reproducer through AST String() and checks the decoded message is unchanged.
  • go test ./... passes locally.

LiteralNode.String trimmed all trailing newlines from Origin, so "|+" lost blank lines on AST round-trip. Keep them for keep chomping, avoid double-counting when joining mapping entries, and credit those blanks in checkLineBreak. Fixes goccy#826.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.65%. Comparing base (edee2f9) to head (af12b69).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #969   +/-   ##
=======================================
  Coverage   80.65%   80.65%           
=======================================
  Files          22       22           
  Lines        6845     6845           
=======================================
  Hits         5521     5521           
  Misses        905      905           
  Partials      419      419           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser lose trailing empty lines after a block scalar with the + indicator

2 participants