parseYaml: drop the stray null when the stream starts with comments#875
Open
c-tonneslan wants to merge 1 commit into
Open
parseYaml: drop the stray null when the stream starts with comments#875c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #660. When a YAML stream begins with comment-only lines before the first
---separator, the chunkedYAMLReaderhands those lines to the decoder as a separate "document" and they unmarshal to nil. So this input: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.jsonnetwith the issue's repro and refreshed the golden.Fixes #660