Skip to content

Fix newline bug on folded scalar - #322

Open
ultimateanu wants to merge 1 commit into
google:mainfrom
ultimateanu:feature/fix-multiline
Open

Fix newline bug on folded scalar#322
ultimateanu wants to merge 1 commit into
google:mainfrom
ultimateanu:feature/fix-multiline

Conversation

@ultimateanu

Copy link
Copy Markdown

Fixes #313

Background

Issue #313 notes that an extra newline is being added to folded block scalars. This is because the yaml_emitter_write_folded_scalar function has this line:

    k := 0

This index variable is used when doing the look ahead from the current point in the scan to determine if we need to add a newline. I believe this is based on libyaml's emitter.c. However in that c library the checks using k are against a custom string type yaml_string_t which maintains an internal offset as evidenced by this line:

    while (string.pointer != string.end)

But in golang, by using k := 0 we are always checking the first character and not correctly doing a look ahead to see if the next line has more linebreaks or blank spaces.

Changes

  • Updated the index k which is used for the look ahead to use i to check from the current point forward
  • Added bounds checks when using k
  • Campground cleanup based on LSP suggests such as removing unnecessary breaks, using modern range/max, remove unused function

Testing

@google-cla

google-cla Bot commented Aug 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ultimateanu

Copy link
Copy Markdown
Author

I did some minor code clean up based on LSP suggestions on pkg/yaml/emitterc.go. I can break that out into a separate commit or PR. FYI, I didn't see other PRs with multiple commits so I didn't do that.

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.

Non-deterministic output for indented multiline strings

1 participant