Skip to content

fix: keep lone newline when marshaling literal block scalars - #968

Open
gyanu2507 wants to merge 1 commit into
goccy:masterfrom
gyanu2507:fix/lone-newline-literal-keep-807
Open

gyanu2507 wants to merge 1 commit into
goccy:masterfrom
gyanu2507:fix/lone-newline-literal-keep-807

Conversation

@gyanu2507

Copy link
Copy Markdown

Fixes #807.

Marshaling a string that is only a newline produced | (clip). Clip strips that only line break, so Unmarshal got back "" instead of "\n".

LiteralBlockHeader now returns |+ when the value is exactly one line-break character. That matches the keep-chomping form |+\n\n, which already round-trips correctly. Other multiline cases are unchanged.

This is separate from #792, which quotes leading whitespace via IsNeedQuoted. The block-header path is what emits | / |+ for newline-containing strings.

Test plan:

  • New TestLiteralBlockHeader cases, including "\n" and "\r".
  • Encoder case expecting |+\n\n for "\n".
  • go test ./... passes locally.

A string that is only "\n" used clip chomping ("|"), so round-trip unmarshaled to "". Use keep ("|+") for that case. Fixes goccy#807.
@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.69%. Comparing base (edee2f9) to head (6cb8860).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #968      +/-   ##
==========================================
+ Coverage   80.65%   80.69%   +0.03%     
==========================================
  Files          22       22              
  Lines        6845     6847       +2     
==========================================
+ Hits         5521     5525       +4     
+ Misses        905      903       -2     
  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.

Wrong marshalling of "\n"

2 participants