Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use YAML document terminators and skip empty documents in parser #268

Merged
merged 2 commits into from
Jun 14, 2021

Conversation

hasheddan
Copy link
Member

@hasheddan hasheddan commented Jun 9, 2021

Description of your changes

YAML supports a document terminator (...) when reading files in a
stream. This allows for the reader to indicate that the current document
has ended without indicating that the stream is finished. Anything after
the document terminator is ignored by the consumer. Therefore, we write
the terminator at the end of a read file, then immediately follow with a
YAML document separator (---), which is mandatory according to the YAML
spec when using document terminators.

Signed-off-by: hasheddan georgedanielmangum@gmail.com

If a document contains only whitespace and we are not able to decode it
into one of the supported schemas, we ignore it and continue. We want to
avoid skipping a type that does not have a registered schema so that we
do not silently ignore errors when package building, but we consider it
safe to assume that a YAML document with no content is safe to skip.

Signed-off-by: hasheddan georgedanielmangum@gmail.com

Reference: https://yaml.org/spec/1.2/spec.html#id2801681

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

I have updated unit tests to demonstrate this functionality, as well as testing on a variety of existing packages. One important distinction here is that consecutive separators (---) or trailing separators in a YAML document can still cause an error as they are interpreted as document begin / end. So multiple consecutive separators can produce a document with literal --- as content and a trailing separator can produce a document with literal ... as content.

Overall, this expands the range of valid YAML that the Crossplane CLI and package manager will accept.

YAML supports a document terminator (...) when reading files in a
stream. This allows for the reader to indicate that the current document
has ended without indicating that the stream is finished. Anything after
the document terminator is ignored by the consumer. Therefore, we write
the terminator at the end of a read file, then immediately follow with a
YAML document separator (---), which is mandatory according to the YAML
spec when using document terminators.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
If a document contains only whitespace and we are not able to decode it
into one of the supported schemas, we ignore it and continue. We want to
avoid skipping a type that does not have a registered schema so that we
do not silently ignore errors when package building, but we consider it
safe to assume that a YAML document with no content is safe to skip.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
@hasheddan hasheddan requested review from negz and muvaf June 9, 2021 16:21
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.

None yet

2 participants