Treat a frontmatter block with no YAML content as unreadable instead of throwing - #149
Merged
Merged
Conversation
…instead of throwing YamlDotNet deserializes a comment-only, `~` or `null` document to null, and TryParseYamlObject then iterated it and threw NullReferenceException out of ExtractBody, ExtractFrontmatter, RemoveFrontmatter and CombineFrontmatter. It now returns false for such a block, the same as for an empty mapping. Fixes #134 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014jCUYfoRMwhybsUaSa1NFm
|
This was referenced Sep 27, 2026
This was referenced Sep 28, 2026
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 #134
What was wrong
YamlDotNet deserializes a YAML document with no content to
null. That covers a comment only (# TODO),~andnull.YamlSerializer.TryParseYamlObjectthen ranforeachover the null result. TheNullReferenceExceptionwasn't one of the caught types, so it escaped fromExtractBody,ExtractFrontmatter,RemoveFrontmatterandCombineFrontmatter.Change
TryParseYamlObjectreturnsfalsewhen the deserialized mapping isnull. Callers already getfalsefor an empty mapping ({}), and they now get the same for these blocks. As a result:ExtractBodyandRemoveFrontmatterreturn the body.ExtractFrontmatterreturnsnull.CombineFrontmatterno longer throws.AddFrontmatteralready refuses to overwrite a block that has text in it but yields no properties, so a placeholder comment isn't silently replaced. That stays the same here, and a test now pins it for these inputs.Tests
New file
EmptyYamlBlockTestshas 6 tests, and each one runs against comment-only,~andnullblocks:ExtractBodyExtractFrontmatterRemoveFrontmatterCombineFrontmatterAddFrontmatterYamlSerializer.TryParseYamlObjectWith
YamlSerializer.csreverted, all 18 new cases fail. With the fix, the full suite passes: 171/171.This PR touches only
YamlSerializer.csand a new test file, so it is independent of #143, #144 and #145.🤖 Generated with Claude Code
https://claude.ai/code/session_014jCUYfoRMwhybsUaSa1NFm
Generated by Claude Code