Skip to content

parseYaml: drop the stray null when the stream starts with comments#875

Open
c-tonneslan wants to merge 1 commit into
google:masterfrom
c-tonneslan:fix-parseyaml-leading-comment
Open

parseYaml: drop the stray null when the stream starts with comments#875
c-tonneslan wants to merge 1 commit into
google:masterfrom
c-tonneslan:fix-parseyaml-leading-comment

Conversation

@c-tonneslan
Copy link
Copy Markdown

Fixes #660. When a YAML stream begins with comment-only lines before the first --- separator, the chunked YAMLReader hands those lines to the decoder as a separate "document" and they unmarshal to nil. So this input:

# Test
---
foo: bar
---
baz: cuux

ends up as [null, {foo: bar}, {baz: cuux}] instead of just the two real documents.

Strip a comment-and-blank prefix that runs up to (and including) the first --- marker before handing the buffer to the YAML reader, but only when there's real content after the marker. That leaves the bare --- case (an explicit single-null document) and any input where actual content comes before the first marker untouched.

Extended testdata/parseYaml.jsonnet with the issue's repro and refreshed the golden.

Fixes #660

When a YAML stream begins with comment-only lines before the first

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
--- separator, the chunked YAMLReader handed those lines to the
decoder as a separate "document" and they unmarshaled to nil. The
result array then contained a leading null the user didn't write.

Strip a comment-and-blank prefix that runs up to (and including) the
first --- marker, but only when the marker is followed by real
content. Leaves the bare  case (an explicit single-null
document) untouched.

Fixes google#660
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.

parseYaml inserts null when document stream starts with a comment

1 participant