Skip to content

Don't add a line to keep scalars before comments - #530

Open
yuyongyan29-dev wants to merge 1 commit into
yaml:mainfrom
yuyongyan29-dev:fix-keep-scalar-foot-comment
Open

yuyongyan29-dev wants to merge 1 commit into
yaml:mainfrom
yuyongyan29-dev:fix-keep-scalar-foot-comment

Conversation

@yuyongyan29-dev

Copy link
Copy Markdown

A Node round trip adds a newline to a keep (+) block scalar when the document ends with a comment, and keeps adding one each time:

$ printf 'key: |+\n  text\n\n# trail\n' | go-yaml -j
{"key":"text\n\n"}
$ printf 'key: |+\n  text\n\n# trail\n' | go-yaml -Y | go-yaml -j
{"key":"text\n\n\n"}

emitDocumentEnd always writes a blank line before the document foot comment; after a keep scalar it is read back as content. It is now skipped in that case only.

Added literal and folded node-roundtrip cases to testdata/node.yaml.

When a document ends with a keep ('+') block scalar and has a foot
comment, the emitter wrote an extra blank line to separate the comment.
That line was read back as part of the scalar, so every Node round trip
appended another newline to the value:

    key: |+
      text

    # trail

decoded "text\n\n" but re-encoded as "text\n\n\n".

Skip the forced document foot separation when the last output was a
keep block scalar; its trailing breaks already separate the comment.
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.

1 participant