Repository navigation
Treat a header with no keys as empty so AddFrontmatter fills it [patch] - #207
Merged
Merged
Conversation
A header that parses but holds no keys (a comment only, ~, null or {})
was reported as unreadable, so AddFrontmatter returned its input unchanged
and CombineFrontmatter would not combine a stacked block beside it. Such a
block is now skipped as empty; only a parse failure or a non-mapping root
still leaves the document alone.
The test that pinned the old AddFrontmatter behaviour is rewritten to the
behaviour the issue asks for.
Fixes #206
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UFB6HgHkLg58aFnXW56N7C
The two catches no test reaches left the new code under the 80% coverage gate; one filter keeps the same exceptions and the same answer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFB6HgHkLg58aFnXW56N7C
|
This was referenced Oct 20, 2026
This was referenced Nov 16, 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 #206
What was wrong
YamlSerializer.TryParseYamlObjectreturns false both when a block fails to parse and when it parses to nothing (# TODO,~,null) or to an empty mapping ({}).ExtractFrontmatterObjectssethasUnreadableBlockfor either case. As a result,AddFrontmatterreturned placeholder-header documents unchanged, which silently dropped the caller's properties, andCombineFrontmatterwould not combine a real block stacked beside an empty one.Change
YamlSerializer.IsEmptyYamlDocument. It deserializes the block asobjectand reports true fornullor an empty mapping.ExtractFrontmatterObjectssetshasUnreadableBlockonly when a block failsTryParseYamlObjectand is not empty. Empty blocks are skipped, the same way whitespace-only blocks already were.TryParseYamlObjectcontract is unchanged: it still returns false for an empty document, and the existingTryParseYamlObject_EmptyYamlDocument_ReturnsFalsetest still pins that.Tests (
EmptyYamlBlockTests)AddFrontmatter_EmptyYamlBlock_AddsThePropertiescovers# TODO: fill in,~,nulland{}. Each now yieldstitle: Helloand keeps the body. This replacesAddFrontmatter_EmptyYamlBlock_LeavesTheDocumentUnchanged, which pinned the behaviour the issue reports as a bug.CombineFrontmatter_EmptyBlockStackedOnARealOne_CombinesThemcovers# c,~and{}stacked ontitle: a, and expects a single header.AddFrontmatter_UnreadableBlock_LeavesTheDocumentUnchangedchecks thatkey: [unclosed, a bare scalar and a sequence root are still left alone.Frontmatter.cschange reverted, all 7 new add and combine cases fail. With the change, the full suite passes, 313/313 locally on net10.0.#180 step 1 will rewrite this parser. These tests are written against the public API, so they should carry over unchanged.
Generated by Claude Code